Skip to content

Instantly share code, notes, and snippets.

View Tony363's full-sized avatar
🎯
Focusing

Tony Siu Tony363

🎯
Focusing
View GitHub Profile
@Tony363
Tony363 / webstuff.txt
Last active September 18, 2023 07:17
Traceback (most recent call last):
File "/root/sec_filings/scrap_links.py", line 68, in <module>
main()
File "/root/sec_filings/scrap_links.py", line 26, in main
driver = webdriver.Chrome(executable_path=args.chrome_driver_path,options=options)
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
Traceback (most recent call last):
File "scrap_links.py", line 67, in <module>
main()
File "scrap_links.py", line 26, in main
driver = webdriver.Chrome(executable_path=args.chrome_driver_path,options=options)
File "/home/seluser/.local/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "/home/seluser/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/seluser/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
import os
import torchvision
import torchvision.transforms as transforms
from torch.utils.data import DataLoader
from datasets import load_dataset, DatasetDict,load_from_disk
def process(
example:dict,
transform:torchvision.transforms
)->dict:
def forward(self, mask_inputs, feat_dis_org_embed, feat_dis_scale_1_embed, feat_dis_scale_2_embed):
# feat_dis_org_embed: batch x (C=384) x (H=24) x (W=32)
# feat_dis_scale_1_embed: batch x (C=384) x (H=9) x (W=12)
# feat_dis_scale_2_embed: batch x (C=384) x (H=5) x (W=7)
# learnable scale embedding
scale_org_embed = repeat(self.scale_org_embedding, '() c () () -> b c h w', b=self.config.batch_size, h=24, w=32)
scale_1_embed = repeat(self.scale_1_embedding, '() c () () -> b c h w', b=self.config.batch_size, h=9, w=12)
scale_2_embed = repeat(self.scale_1_embedding, '() c () () -> b c h w', b=self.config.batch_size, h=5, w=7)
""" train model """
def train_epoch(config, epoch, model_transformer, model_backbone, criterion, optimizer, scheduler, train_loader):
losses = []
model_transformer.train()
model_backbone.train()
# input mask (batch_size x len_sqe+1)
mask_inputs = torch.ones(config.batch_size, config.n_enc_seq+1).to(config.device)
# save data for one epoch
def _get_batch_logps(logits: torch.FloatTensor, labels: torch.LongTensor, average_log_prob: bool = False) -> torch.FloatTensor:
"""Compute the log probabilities of the given labels under the given logits.
Args:
logits: Logits of the model (unnormalized). Shape: (batch_size, sequence_length, vocab_size)
labels: Labels for which to compute the log probabilities. Label tokens with a value of -100 are ignored. Shape: (batch_size, sequence_length)
average_log_prob: If True, return the average log probability per (non-masked) token. Otherwise, return the sum of the log probabilities of the (non-masked) tokens.
Returns:
A tensor of shape (batch_size,) containing the average/sum log probabilities of the given labels under the given logits.
def classification_report(y_test, y_pred):
# calculate precision, recall, f1-score
# TODO:
cm = confusion_matrix(y_test,y_pred)
precision = cm[1,1]/(cm[1,1] + cm[0,1])
recall = cm[1,1]/(cm[1,1] + cm[1,0])
f1 = 2*(precision * recall)/(precision + recall)
acc = (cm[1,1] + cm[0,0]) / np.sum(cm.flatten())
# end TODO
return(precision,recall,f1,acc)
class Loader(object):
def __init__(
self,
non_flicker_dir: str,
flicker_dir: str,
labels: dict,
batch_size: int,
in_mem_batches: int,
) -> None:
mp.set_start_method("spawn")
def torch_training(
ds_train: Streamer,
ds_val: Streamer,
model: nn.Module,
optimizer: torch.optim.Optimizer,
epochs: int = 1000,
criterion=nn.BCELoss(),
f1_torch=f1_score # F1_Loss().cuda(),
) -> nn.Module:
import torch
import numpy as np
import torch.nn as nn
class LSTMModel(nn.Module):
def __init__(self, input_dim, hidden_dim, layer_dim, output_dim):
super(LSTMModel, self).__init__()
# Hidden dimensions
self.hidden_dim = hidden_dim