diff --git a/docs/source/notes/combine_methods.md b/docs/source/notes/combine_methods.md index 38348f1..dc84ce4 100644 --- a/docs/source/notes/combine_methods.md +++ b/docs/source/notes/combine_methods.md @@ -18,15 +18,15 @@ The following describes each supported method and whether or not it requires bot | gating_on_cat_and_num_feats_then_sum | Gated summation of transformer outputs, numerical feats, and categorical feats before final classifier layer(s). Inspired by [Integrating Multimodal Information in Large Pretrained Transformers](https://www.aclweb.org/anthology/2020.acl-main.214.pdf) which performs the mechanism for each token. | False | weighted_feature_sum_on_transformer_cat_and_numerical_feats | Learnable weighted feature-wise sum of transformer outputs, numerical feats and categorical feats for each feature dimension before final classifier layer(s) | False -This table shows the the equations involved with each method. First we define some notation +This table shows the the equations involved with each method. First we define some notations: -* ![equation](https://latex.codecogs.com/svg.latex?%5Cinline%20%5Cmathbf%7Bm%7D) denotes the combined multimodal features -* ![equation](https://latex.codecogs.com/svg.latex?%5Cinline%20%5Cmathbf%7Bx%7D) denotes the output text features from the transformer -* ![equation](https://latex.codecogs.com/svg.latex?%5Cinline%20%5Cmathbf%7Bc%7D) denotes the categorical features -* ![equation](https://latex.codecogs.com/svg.latex?%5Cinline%20%5Cmathbf%7Bn%7D) denotes the numerical features -* ![equation](https://latex.codecogs.com/svg.latex?%5Cinline%20h_%7B%5Cmathbf%7B%5CTheta%7D%7D) denotes a MLP parameterized by ![equation](https://latex.codecogs.com/svg.latex?%5Cinline%20%5Cmathbf%7B%5CTheta%7D) -* ![equation](https://latex.codecogs.com/svg.latex?%5Cmathbf%7BW%7D) denotes a weight matrix -* ![equation](https://latex.codecogs.com/svg.latex?b) denotes a scalar bias +* ![m](https://latex.codecogs.com/svg.latex?%5Cinline%20%5Cmathbf%7Bm%7D) denotes the combined multimodal features +* ![x](https://latex.codecogs.com/svg.latex?%5Cinline%20%5Cmathbf%7Bx%7D) denotes the output text features from the transformer +* ![c](https://latex.codecogs.com/svg.latex?%5Cinline%20%5Cmathbf%7Bc%7D) denotes the categorical features +* ![n](https://latex.codecogs.com/svg.latex?%5Cinline%20%5Cmathbf%7Bn%7D) denotes the numerical features +* ![h_theta](https://latex.codecogs.com/svg.latex?%5Cinline%20h_%7B%5Cmathbf%7B%5CTheta%7D%7D) denotes a MLP parameterized by ![theta](https://latex.codecogs.com/svg.latex?%5Cinline%20%5Cmathbf%7B%5CTheta%7D) +* ![W](https://latex.codecogs.com/svg.latex?%5Cmathbf%7BW%7D) denotes a weight matrix +* ![b](https://latex.codecogs.com/svg.latex?b) denotes a scalar bias | Combine Feat Method | Equation | |:--------------|:-------------------| diff --git a/docs/source/notes/introduction.rst b/docs/source/notes/introduction.rst index f786320..0d7654f 100644 --- a/docs/source/notes/introduction.rst +++ b/docs/source/notes/introduction.rst @@ -32,7 +32,6 @@ Say for example we had categorical features of dim 9 and numerical features of d cat_feat_dim=9, # need to specify this numerical_feat_dim=5, # need to specify this num_labels=2, # need to specify this, assuming our task is binary classification - use_num_bn=False, ) bert_config.tabular_config = tabular_config diff --git a/main.py b/main.py index 4169636..c2033d1 100644 --- a/main.py +++ b/main.py @@ -200,7 +200,7 @@ def compute_metrics_fn(p: EvalPrediction): ) if training_args.do_train: trainer.train( - model_path=model_args.model_name_or_path + resume_from_checkpoint=model_args.model_name_or_path if os.path.isdir(model_args.model_name_or_path) else None ) diff --git a/multimodal_exp_args.py b/multimodal_exp_args.py index 0d28968..0c3ff25 100644 --- a/multimodal_exp_args.py +++ b/multimodal_exp_args.py @@ -4,7 +4,11 @@ from typing import Optional, Tuple, List import torch -from transformers.training_args import TrainingArguments, requires_backends, cached_property +from transformers.training_args import ( + TrainingArguments, + requires_backends, + cached_property, +) logger = logging.getLogger(__name__) @@ -17,20 +21,30 @@ class ModelArguments: """ model_name_or_path: str = field( - metadata={"help": "Path to pretrained model or model identifier from huggingface.co/models"} + metadata={ + "help": "Path to pretrained model or model identifier from huggingface.co/models" + } ) config_name: Optional[str] = field( - default=None, metadata={"help": "Pretrained config name or path if not the same as model_name"} + default=None, + metadata={ + "help": "Pretrained config name or path if not the same as model_name" + }, ) tokenizer_name: Optional[str] = field( - default=None, metadata={"help": "Pretrained tokenizer name or path if not the same as model_name"} + default=None, + metadata={ + "help": "Pretrained tokenizer name or path if not the same as model_name" + }, ) cache_dir: Optional[str] = field( - default=None, metadata={"help": "Where do you want to store the pretrained models downloaded from s3"} + default=None, + metadata={ + "help": "Where do you want to store the pretrained models downloaded from s3" + }, ) - @dataclass class MultimodalDataTrainingArguments: """ @@ -40,185 +54,189 @@ class MultimodalDataTrainingArguments: the command line. """ - data_path: str = field(metadata={ - 'help': 'the path to the csv files containing the dataset. If create_folds is set to True' - 'then it is expected that data_path points to one csv containing the entire dataset' - 'to split into folds. Otherwise, data_path should be the folder containing' - 'train.csv, test.csv, (and val.csv if available)' - }) - create_folds: bool = field(default=False, - metadata={'help': 'Whether or not we want to create folds for ' - 'K fold evaluation of the model'}) - - num_folds: int = field(default=5, - metadata={'help': 'The number of folds for K fold ' - 'evaluation of the model. Will not be used if create_folds is False'}) - validation_ratio: float = field(default=0.2, - metadata={'help': 'The ratio of dataset examples to be used for validation across' - 'all folds for K fold evaluation. If num_folds is 5 and ' - 'validation_ratio is 0.2. Then a consistent 20% of the examples will' - 'be used for validation for all folds. Then the remaining 80% is used' - 'for K fold split for test and train sets so 0.2*0.8=16% of ' - 'all examples is used for testing and 0.8*0.8=64% of all examples' - 'is used for training for each fold'} - ) - num_classes: int = field(default=-1, - metadata={'help': 'Number of labels for classification if any'}) + data_path: str = field( + metadata={ + "help": "the path to the csv files containing the dataset. If create_folds is set to True" + "then it is expected that data_path points to one csv containing the entire dataset" + "to split into folds. Otherwise, data_path should be the folder containing" + "train.csv, test.csv, (and val.csv if available)" + } + ) + create_folds: bool = field( + default=False, + metadata={ + "help": "Whether or not we want to create folds for " + "K fold evaluation of the model" + }, + ) + + num_folds: int = field( + default=5, + metadata={ + "help": "The number of folds for K fold " + "evaluation of the model. Will not be used if create_folds is False" + }, + ) + validation_ratio: float = field( + default=0.2, + metadata={ + "help": "The ratio of dataset examples to be used for validation across" + "all folds for K fold evaluation. If num_folds is 5 and " + "validation_ratio is 0.2. Then a consistent 20% of the examples will" + "be used for validation for all folds. Then the remaining 80% is used" + "for K fold split for test and train sets so 0.2*0.8=16% of " + "all examples is used for testing and 0.8*0.8=64% of all examples" + "is used for training for each fold" + }, + ) + num_classes: int = field( + default=-1, metadata={"help": "Number of labels for classification if any"} + ) column_info_path: str = field( default=None, metadata={ - 'help': 'the path to the json file detailing which columns are text, categorical, numerical, and the label' - }) + "help": "the path to the json file detailing which columns are text, categorical, numerical, and the label" + }, + ) column_info: dict = field( default=None, metadata={ - 'help': 'a dict referencing the text, categorical, numerical, and label columns' - 'its keys are text_cols, num_cols, cat_cols, and label_col' - }) - - categorical_encode_type: str = field(default='ohe', - metadata={ - 'help': 'sklearn encoder to use for categorical data', - 'choices': ['ohe', 'binary', 'label', 'none'] - }) - numerical_transformer_method: str = field(default='yeo_johnson', - metadata={ - 'help': 'sklearn numerical transformer to preprocess numerical data', - 'choices': ['yeo_johnson', 'box_cox', 'quantile_normal', 'none'] - }) - task: str = field(default="classification", - metadata={ - "help": "The downstream training task", - "choices": ["classification", "regression"] - }) - - mlp_division: int = field(default=4, - metadata={ - 'help': 'the ratio of the number of ' - 'hidden dims in a current layer to the next MLP layer' - }) - combine_feat_method: str = field(default='individual_mlps_on_cat_and_numerical_feats_then_concat', - metadata={ - 'help': 'method to combine categorical and numerical features, ' - 'see README for all the method' - }) - mlp_dropout: float = field(default=0.1, - metadata={ - 'help': 'dropout ratio used for MLP layers' - }) - numerical_bn: bool = field(default=True, - metadata={ - 'help': 'whether to use batchnorm on numerical features' - }) - use_simple_classifier: str = field(default=True, - metadata={ - 'help': 'whether to use single layer or MLP as final classifier' - }) - mlp_act: str = field(default='relu', - metadata={ - 'help': 'the activation function to use for finetuning layers', - 'choices': ['relu', 'prelu', 'sigmoid', 'tanh', 'linear'] - }) - gating_beta: float = field(default=0.2, - metadata={ - 'help': "the beta hyperparameters used for gating tabular data " - "see https://www.aclweb.org/anthology/2020.acl-main.214.pdf" - }) + "help": "a dict referencing the text, categorical, numerical, and label columns" + "its keys are text_cols, num_cols, cat_cols, and label_col" + }, + ) + + categorical_encode_type: str = field( + default="ohe", + metadata={ + "help": "sklearn encoder to use for categorical data", + "choices": ["ohe", "binary", "label", "none"], + }, + ) + numerical_transformer_method: str = field( + default="yeo_johnson", + metadata={ + "help": "sklearn numerical transformer to preprocess numerical data", + "choices": ["yeo_johnson", "box_cox", "quantile_normal", "none"], + }, + ) + task: str = field( + default="classification", + metadata={ + "help": "The downstream training task", + "choices": ["classification", "regression"], + }, + ) + + mlp_division: int = field( + default=4, + metadata={ + "help": "the ratio of the number of " + "hidden dims in a current layer to the next MLP layer" + }, + ) + combine_feat_method: str = field( + default="individual_mlps_on_cat_and_numerical_feats_then_concat", + metadata={ + "help": "method to combine categorical and numerical features, " + "see README for all the method" + }, + ) + mlp_dropout: float = field( + default=0.1, metadata={"help": "dropout ratio used for MLP layers"} + ) + numerical_bn: bool = field( + default=True, + metadata={"help": "whether to use batchnorm on numerical features"}, + ) + categorical_bn: bool = field( + default=True, + metadata={"help": "whether to use batchnorm on categorical features"}, + ) + use_simple_classifier: str = field( + default=True, + metadata={"help": "whether to use single layer or MLP as final classifier"}, + ) + mlp_act: str = field( + default="relu", + metadata={ + "help": "the activation function to use for finetuning layers", + "choices": ["relu", "prelu", "sigmoid", "tanh", "linear"], + }, + ) + gating_beta: float = field( + default=0.2, + metadata={ + "help": "the beta hyperparameters used for gating tabular data " + "see https://www.aclweb.org/anthology/2020.acl-main.214.pdf" + }, + ) def __post_init__(self): - assert self.column_info != self.column_info_path, 'provide either a path to column_info or a dictionary' - assert 0 <= self.validation_ratio <= 1, 'validation_ratio must be between 0 and 1' + assert ( + self.column_info != self.column_info_path + ), "provide either a path to column_info or a dictionary" + assert ( + 0 <= self.validation_ratio <= 1 + ), "validation_ratio must be between 0 and 1" if self.column_info is None and self.column_info_path: - with open(self.column_info_path, 'r') as f: + with open(self.column_info_path, "r") as f: self.column_info = json.load(f) - assert 'text_cols' in self.column_info and 'label_col' in self.column_info - if 'cat_cols' not in self.column_info: - self.column_info['cat_cols'] = None - self.categorical_encode_type = 'none' - if 'num_cols' not in self.column_info: - self.column_info['num_cols'] = None - self.numerical_transformer_method = 'none' - if 'text_col_sep_token' not in self.column_info: - self.column_info['text_col_sep_token'] = None + assert "text_cols" in self.column_info and "label_col" in self.column_info + if "cat_cols" not in self.column_info: + self.column_info["cat_cols"] = None + self.categorical_encode_type = "none" + if "num_cols" not in self.column_info: + self.column_info["num_cols"] = None + self.numerical_transformer_method = "none" + if "text_col_sep_token" not in self.column_info: + self.column_info["text_col_sep_token"] = None + @dataclass class OurTrainingArguments(TrainingArguments): experiment_name: Optional[str] = field( - default=None, - metadata={'help': 'A name for the experiment'} - ) - - gpu_num: int = field( - default=0, - metadata={'help': 'The gpu number to train on'} + default=None, metadata={"help": "A name for the experiment"} ) debug_dataset: bool = field( default=False, - metadata={'help': 'Whether we are training in debug mode (smaller model)'} + metadata={"help": "Whether we are training in debug mode (smaller model)"}, ) debug_dataset_size: int = field( default=100, - metadata={'help': 'Size of the dataset in debug mode. Only used when debug_dataset = True.'} + metadata={ + "help": "Size of the dataset in debug mode. Only used when debug_dataset = True." + }, ) - do_eval: bool = field(default=True, metadata={"help": "Whether to run eval on the dev set."}) - do_predict: bool = field(default=True, metadata={"help": "Whether to run predictions on the test set."}) - - evaluate_during_training: bool = field( - default=True, metadata={"help": "Run evaluation during training at each logging step."}, + do_eval: bool = field( + default=True, metadata={"help": "Whether to run eval on the dev set."} + ) + do_predict: bool = field( + default=True, metadata={"help": "Whether to run predictions on the test set."} ) max_token_length: Optional[int] = field( - default=None, - metadata={'help': 'The maximum token length'} + default=None, metadata={"help": "The maximum token length"} ) gradient_accumulation_steps: int = field( default=1, - metadata={"help": "Number of updates steps to accumulate before performing a backward/update pass."}, + metadata={ + "help": "Number of updates steps to accumulate before performing a backward/update pass." + }, ) - learning_rate: float = field(default=5e-5, metadata={"help": "The initial learning rate for Adam."}) - - report_to: Optional[List[str]] = field( - default_factory=list, metadata={"help": "The list of integrations to report the results and logs to."} + learning_rate: float = field( + default=5e-5, metadata={"help": "The initial learning rate for Adam."} ) def __post_init__(self): + super().__post_init__() if self.debug_dataset: self.max_token_length = 16 self.logging_steps = 5 self.overwrite_output_dir = True - - - @cached_property - def _setup_devices(self) -> Tuple["torch.device", int]: - requires_backends(self, ["torch"]) - logger.info("PyTorch: setting up devices") - if self.no_cuda: - device = torch.device("cpu") - self._n_gpu = 0 - elif self.local_rank == -1: - # if n_gpu is > 1 we'll use nn.DataParallel. - # If you only want to use a specific subset of GPUs use `CUDA_VISIBLE_DEVICES=0` - # Explicitly set CUDA to the first (index 0) CUDA device, otherwise `set_device` will - # trigger an error that a device index is missing. Index 0 takes into account the - # GPUs available in the environment, so `CUDA_VISIBLE_DEVICES=1,2` with `cuda:0` - # will use the first GPU in that env, i.e. GPU#1 - device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") - self._n_gpu = torch.cuda.device_count() - else: - # Here, we'll use torch.distributed. - # Initializes the distributed backend which will take care of sychronizing nodes/GPUs - if not torch.distributed.is_initialized(): - torch.distributed.init_process_group(backend="nccl", timeout=self.ddp_timeout_delta) - device = torch.device("cuda", self.local_rank) - self._n_gpu = 1 - - if device.type == "cuda": - torch.cuda.set_device(device) - - return device \ No newline at end of file diff --git a/multimodal_transformers/__init__.py b/multimodal_transformers/__init__.py index 5b016a2..7a2920d 100644 --- a/multimodal_transformers/__init__.py +++ b/multimodal_transformers/__init__.py @@ -1,6 +1,6 @@ import multimodal_transformers.data import multimodal_transformers.model -__version__ = "0.2-alpha" +__version__ = "0.3.0" __all__ = ["multimodal_transformers", "__version__"] diff --git a/multimodal_transformers/model/tabular_combiner.py b/multimodal_transformers/model/tabular_combiner.py index 770324f..cf56114 100644 --- a/multimodal_transformers/model/tabular_combiner.py +++ b/multimodal_transformers/model/tabular_combiner.py @@ -95,17 +95,13 @@ def __init__(self, tabular_config): self.numerical_feat_dim = tabular_config.numerical_feat_dim self.num_labels = tabular_config.num_labels self.numerical_bn = tabular_config.numerical_bn + self.categorical_bn = tabular_config.categorical_bn self.mlp_act = tabular_config.mlp_act self.mlp_dropout = tabular_config.mlp_dropout self.mlp_division = tabular_config.mlp_division self.text_out_dim = tabular_config.text_feat_dim self.tabular_config = tabular_config - if self.numerical_bn and self.numerical_feat_dim > 0: - self.num_bn = nn.BatchNorm1d(self.numerical_feat_dim) - else: - self.num_bn = None - if self.combine_feat_method == "text_only": self.final_out_dim = self.text_out_dim elif self.combine_feat_method == "concat": @@ -131,7 +127,7 @@ def __init__(self, tabular_config): dropout_prob=self.mlp_dropout, hidden_channels=dims, return_layer_outs=False, - bn=True, + bn=self.categorical_bn, ) self.final_out_dim = ( self.text_out_dim + output_dim + self.numerical_feat_dim @@ -157,7 +153,7 @@ def __init__(self, tabular_config): dropout_prob=self.mlp_dropout, hidden_channels=dims, return_layer_outs=False, - bn=True, + bn=self.categorical_bn and self.numerical_bn, ) self.final_out_dim = self.text_out_dim + output_dim elif ( @@ -181,7 +177,7 @@ def __init__(self, tabular_config): dropout_prob=self.mlp_dropout, hidden_channels=dims, return_layer_outs=False, - bn=True, + bn=self.categorical_bn, ) output_dim_num = 0 @@ -194,7 +190,7 @@ def __init__(self, tabular_config): dropout_prob=self.mlp_dropout, num_hidden_lyr=1, return_layer_outs=False, - bn=True, + bn=self.numerical_bn, ) self.final_out_dim = self.text_out_dim + output_dim_num + output_dim_cat elif ( @@ -220,7 +216,7 @@ def __init__(self, tabular_config): dropout_prob=self.mlp_dropout, hidden_channels=dims, return_layer_outs=False, - bn=True, + bn=self.categorical_bn, ) else: self.cat_layer = nn.Linear(self.cat_feat_dim, output_dim_cat) @@ -242,7 +238,7 @@ def __init__(self, tabular_config): dropout_prob=self.mlp_dropout, hidden_channels=dims, return_layer_outs=False, - bn=True, + bn=self.numerical_bn, ) else: self.num_layer = nn.Linear(self.numerical_feat_dim, output_dim_num) @@ -275,7 +271,7 @@ def __init__(self, tabular_config): dropout_prob=self.mlp_dropout, return_layer_outs=False, hidden_channels=dims, - bn=True, + bn=self.categorical_bn, ) else: output_dim_cat = self.cat_feat_dim @@ -297,7 +293,7 @@ def __init__(self, tabular_config): dropout_prob=self.mlp_dropout, return_layer_outs=False, hidden_channels=dims, - bn=True, + bn=self.numerical_bn, ) else: output_dim_num = self.numerical_feat_dim @@ -330,7 +326,7 @@ def __init__(self, tabular_config): dropout_prob=self.mlp_dropout, hidden_channels=dims, return_layer_outs=False, - bn=True, + bn=self.categorical_bn, ) self.g_cat_layer = nn.Linear( self.text_out_dim + min(self.text_out_dim, self.cat_feat_dim), @@ -357,7 +353,7 @@ def __init__(self, tabular_config): dropout_prob=self.mlp_dropout, hidden_channels=dims, return_layer_outs=False, - bn=True, + bn=self.numerical_bn, ) self.g_num_layer = nn.Linear( min(self.numerical_feat_dim, self.text_out_dim) + self.text_out_dim, @@ -398,9 +394,6 @@ def forward(self, text_feats, cat_feats=None, numerical_feats=None): text_feats.device ) - if self.numerical_bn and self.numerical_feat_dim != 0: - numerical_feats = self.num_bn(numerical_feats) - if self.combine_feat_method == "text_only": combined_feats = text_feats if self.combine_feat_method == "concat": diff --git a/multimodal_transformers/model/tabular_config.py b/multimodal_transformers/model/tabular_config.py index 9b18f5e..eb160c2 100644 --- a/multimodal_transformers/model/tabular_config.py +++ b/multimodal_transformers/model/tabular_config.py @@ -9,6 +9,7 @@ class TabularConfig: See :obj:`TabularFeatCombiner` for details on the supported methods. mlp_dropout (float): dropout ratio used for MLP layers numerical_bn (bool): whether to use batchnorm on numerical features + categorical_bn (bool): whether to use batchnorm on categorical features use_simple_classifier (bool): whether to use single layer or MLP as final classifier mlp_act (str): the activation function to use for finetuning layers gating_beta (float): the beta hyperparameters used for gating tabular data @@ -25,6 +26,7 @@ def __init__( combine_feat_method="text_only", mlp_dropout=0.1, numerical_bn=True, + categorical_bn=True, use_simple_classifier=True, mlp_act="relu", gating_beta=0.2, @@ -36,6 +38,7 @@ def __init__( self.combine_feat_method = combine_feat_method self.mlp_dropout = mlp_dropout self.numerical_bn = numerical_bn + self.categorical_bn = categorical_bn self.use_simple_classifier = use_simple_classifier self.mlp_act = mlp_act self.gating_beta = gating_beta diff --git a/multimodal_transformers/model/tabular_transformers.py b/multimodal_transformers/model/tabular_transformers.py index 2853c2a..063fa33 100644 --- a/multimodal_transformers/model/tabular_transformers.py +++ b/multimodal_transformers/model/tabular_transformers.py @@ -492,6 +492,7 @@ def __init__(self, hf_model_config): self.config.tabular_config = tabular_config.__dict__ tabular_config.text_feat_dim = hf_model_config.hidden_size + tabular_config.hidden_dropout_prob = hf_model_config.hidden_dropout_prob self.tabular_combiner = TabularFeatCombiner(tabular_config) self.num_labels = tabular_config.num_labels combined_feat_dim = self.tabular_combiner.final_out_dim @@ -603,6 +604,7 @@ def __init__(self, hf_model_config): self.config.tabular_config = tabular_config.__dict__ tabular_config.text_feat_dim = hf_model_config.hidden_size + tabular_config.hidden_dropout_prob = hf_model_config.hidden_dropout_prob self.tabular_combiner = TabularFeatCombiner(tabular_config) self.num_labels = tabular_config.num_labels combined_feat_dim = self.tabular_combiner.final_out_dim diff --git a/notebooks/longformer_text_w_tabular_classification.ipynb b/notebooks/longformer_text_w_tabular_classification.ipynb index 0f1ebf5..3a389cc 100644 --- a/notebooks/longformer_text_w_tabular_classification.ipynb +++ b/notebooks/longformer_text_w_tabular_classification.ipynb @@ -20,14 +20,7 @@ }, { "cell_type": "code", - "source": [ - "gpu_info = !nvidia-smi\n", - "gpu_info = '\\n'.join(gpu_info)\n", - "if gpu_info.find('failed') >= 0:\n", - " print('Not connected to a GPU')\n", - "else:\n", - " print(gpu_info)" - ], + "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -35,11 +28,10 @@ "id": "UWEp8fjltYc5", "outputId": "94adc575-8962-4ddc-ba42-3075056dee3f" }, - "execution_count": 1, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "Thu May 18 14:06:49 2023 \n", "+-----------------------------------------------------------------------------+\n", @@ -63,20 +55,19 @@ "+-----------------------------------------------------------------------------+\n" ] } + ], + "source": [ + "gpu_info = !nvidia-smi\n", + "gpu_info = '\\n'.join(gpu_info)\n", + "if gpu_info.find('failed') >= 0:\n", + " print('Not connected to a GPU')\n", + "else:\n", + " print(gpu_info)" ] }, { "cell_type": "code", - "source": [ - "from psutil import virtual_memory\n", - "ram_gb = virtual_memory().total / 1e9\n", - "print('Your runtime has {:.1f} gigabytes of available RAM\\n'.format(ram_gb))\n", - "\n", - "if ram_gb < 20:\n", - " print('Not using a high-RAM runtime')\n", - "else:\n", - " print('You are using a high-RAM runtime!')" - ], + "execution_count": 2, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -84,17 +75,26 @@ "id": "GbmTRG_WtaEz", "outputId": "ac0bab98-3729-4dd5-f26a-daa9e580b434" }, - "execution_count": 2, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "Your runtime has 89.6 gigabytes of available RAM\n", "\n", "You are using a high-RAM runtime!\n" ] } + ], + "source": [ + "from psutil import virtual_memory\n", + "ram_gb = virtual_memory().total / 1e9\n", + "print('Your runtime has {:.1f} gigabytes of available RAM\\n'.format(ram_gb))\n", + "\n", + "if ram_gb < 20:\n", + " print('Not using a high-RAM runtime')\n", + "else:\n", + " print('You are using a high-RAM runtime!')" ] }, { @@ -110,8 +110,8 @@ }, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", "Collecting git+https://github.com/jtfields/Multimodal-Toolkit-Longformer.git\n", @@ -222,7 +222,6 @@ ] }, { - "output_type": "display_data", "data": { "application/vnd.colab-display-data+json": { "pip_warning": { @@ -232,7 +231,8 @@ } } }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], "source": [ @@ -241,9 +241,7 @@ }, { "cell_type": "code", - "source": [ - "!pip install transformers==4.28.0" - ], + "execution_count": 4, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -251,11 +249,10 @@ "id": "eFkmjDkDLmtL", "outputId": "219f0577-5dc7-4c6b-9d5f-5155202a7a7c" }, - "execution_count": 4, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", "Collecting transformers==4.28.0\n", @@ -284,6 +281,9 @@ "Successfully installed transformers-4.28.0\n" ] } + ], + "source": [ + "!pip install transformers==4.28.0" ] }, { @@ -298,8 +298,8 @@ }, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "Mounted at /content/drive\n" ] @@ -388,39 +388,16 @@ "cell_type": "code", "execution_count": 8, "metadata": { - "id": "Ql8mJlKAUWX5", "colab": { "base_uri": "https://localhost:8080/", "height": 354 }, + "id": "Ql8mJlKAUWX5", "outputId": "5ebf0b87-84bf-4fce-a8de-3d9de8ab60a2" }, "outputs": [ { - "output_type": "execute_result", "data": { - "text/plain": [ - " Unnamed: 0 Clothing ID Age Title \\\n", - "0 0 767 33 NaN \n", - "1 1 1080 34 NaN \n", - "2 2 1077 60 Some major design flaws \n", - "3 3 1049 50 My favorite buy! \n", - "4 4 847 47 Flattering shirt \n", - "\n", - " Review Text Rating Recommended IND \\\n", - "0 Absolutely wonderful - silky and sexy and comf... 4 1 \n", - "1 Love this dress! it's sooo pretty. i happene... 5 1 \n", - "2 I had such high hopes for this dress and reall... 3 0 \n", - "3 I love, love, love this jumpsuit. it's fun, fl... 5 1 \n", - "4 This shirt is very flattering to all due to th... 5 1 \n", - "\n", - " Positive Feedback Count Division Name Department Name Class Name \n", - "0 0 Initmates Intimate Intimates \n", - "1 4 General Dresses Dresses \n", - "2 0 General Dresses Dresses \n", - "3 0 General Petite Bottoms Pants \n", - "4 6 General Tops Blouses " - ], "text/html": [ "\n", "
"
+ ],
+ "text/plain": [
+ "