This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
The module provides three public classes that implement *Bayesian Invariant Risk Minimization* (BIRM) | |
training objectives for causal language‑model fine-tuning: | |
* :class:`EnvironmentEMB` – a lightweight environment embedding that is | |
randomly perturbed at every forward pass to approximate the posterior over | |
domain‑specific linear classifiers. | |
* :class:`BIRMCoefficientScheduler` – a helper that dynamically rescales the | |
BIRM penalty so that its contribution to the total loss remains in a desired | |
ratio to the empirical risk (ERM) term. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subreddit_name = 'marvel' | |
num_comments = 500 # the number of comments you want to get | |
import requests | |
import pandas as pd | |
from datetime import datetime | |
# we use this function to convert responses to dataframes | |
def df_from_response(res): | |
# initialize temp dataframe for batch of data in response |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model_mixed = models.alexnet(pretrained=True) | |
layers_to_unfreeze = 5 | |
for param in model_mixed.features[:-layers_to_unfreeze].parameters(): | |
param.requires_grad = False | |
num_features = 9216 | |
model_mixed.classifier = nn.Sequential( | |
nn.Dropout(p=0.5, inplace=False), | |
nn.Linear(num_features, 2, bias=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data_transforms = { | |
'train': transforms.Compose([ | |
transforms.Resize(600), | |
transforms.ColorJitter(brightness=.3, hue=.5, contrast=.1, saturation=.1), | |
transforms.RandomRotation(degrees=30), | |
transforms.RandomPerspective(distortion_scale=.3, p=.7), | |
transforms.RandomHorizontalFlip(p=.5), | |
transforms.ToTensor(), | |
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]), | |
transforms.RandomErasing(p=.3, scale=(0.01, 0.02)) |