sudo apt update && sudo apt upgrade๐
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
| from transformers import Trainer, TrainingArguments | |
| training_args = TrainingArguments( | |
| output_dir="./logs/model_name", | |
| logging_dir="./logs/runs", | |
| overwrite_output_dir=True, | |
| do_train=True, | |
| per_device_train_batch_size=32, | |
| num_train_epochs=1, | |
| evaluate_during_training=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
| from multimodal_transformers.model import AutoModelWithTabular, TabularConfig | |
| from transformers import AutoConfig | |
| num_labels = len(np.unique(torch_dataset, labels)) | |
| config = AutoConfig.from_pretrained('bert-base-uncased') | |
| tabular_config = TabularConfig( | |
| num_labels=num_labels, | |
| cat_feat_dim=torch_dataset.cat_feats.shape[1], | |
| numerical_feat_dim=torch_dataset.numerical_feats.shape[1], | |
| combine_feat_method='weighted_feature_sum_on_transformer_cat_and_numerical_feats', |
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
| import pandas as pd | |
| from multimodal_transformers.data import load_data | |
| from transformers import AutoTokenizer | |
| data_df = pd.read_csv('Womens Clothing E-Commerce Reviews.csv') | |
| text_cols = ['Title', 'Review Text'] | |
| # The label col is expected to contain integers from 0 to N_classes - 1 | |
| label_col = 'Recommended IND' | |
| categorical_cols = ['Clothing ID', 'Division Name', 'Department Name', 'Class Name'] | |
| numerical_cols = ['Rating', 'Age', 'Positive Feedback Count'] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| """ | |
| An implementation of the pytorch Subset that returns an instance of the original dataset with a reduced number of items. | |
| This has two benefits: | |
| - It allows to stil access the attributes of the Dataset class, such as methods, or properties. | |
| - You can use the usual python index notation with slices to chunk the dataset, rather than creating a list of indices | |
| """ | |
| class Dataset(object): | |
| def __init__(self, iterable): | |
| self.items = iterable |
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
| import json | |
| import numpy as np | |
| from pycocotools import mask | |
| from skimage import measure | |
| ground_truth_binary_mask = np.array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], | |
| [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], | |
| [ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0], | |
| [ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0], | |
| [ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0], |
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
| from pycocotools.coco import COCO | |
| import numpy as np | |
| import cv2 | |
| import os | |
| coco_dataset_path = "/export/public/MS-COCO-2017/" | |
| coco = COCO(coco_dataset_path + "annotations/instances_val2017.json") | |
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
| import tensorflow as tf | |
| def _bytestring_feature(list_of_bytestrings): | |
| return tf.train.Feature(bytes_list=tf.train.BytesList(value=list_of_bytestrings)) | |
| def _int_feature(list_of_ints): # int64 | |
| return tf.train.Feature(int64_list=tf.train.Int64List(value=list_of_ints)) |
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
| import argparse | |
| import math | |
| import os | |
| import numpy as np | |
| import pandas as pd | |
| import tensorflow as tf | |
| _BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |