#!pip install torchtext==0.8.0 torch==1.7.1 pytorch-lightning==1.2.2 from typing import…
- User
#!pip install torchtext==0.8.0 torch==1.7.1 pytorch-lightning==1.2.2
from typing import List, Dict import torch from pandas import DataFrame from torch.utils.data import Dataset from torch.utils.data.dataset import T_co from transformers import PreTrainedTokenizer import pandas as pd import numpy as np from sklearn import preprocessing
def collate_batch(featurized_samples: List[Dict]): input_ids = torch.nn.utils.rnn.pad_sequence( [torch.tensor(x['input_ids']) for x in featurized_samples], batch_first=True)
codeattention_masks = torch.nn.utils.rnn.pad_sequence( [torch.tensor(x['attention_mask']) for x in featurized_samples], batch_first=True) batch = {"input_ids": input_ids, "attention_masks": attention_masks, "tokens": [x['tokens'] for x in featurized_samples], "targets": np.array([x['target'] for x in featurized_samples]), "ad_ids": [x['ad_id'] for x in featurized_samples]} if 'token_type_ids' in featurized_samples[0]: token_type_ids = torch.nn.utils.rnn.pad_sequence( [torch.tensor(x['token_type_ids']) for x in featurized_samples], batch_first=True) batch["token_type_ids"] = token_type_ids return batchdef sample_to_features(sample: pd.Series, tokenizer: PreTrainedTokenizer, label_column: str, max_length=512) -> Dict: # input_text = sample["jobTitle"] + " " + sample["description"] input_text = sample["description"]
codetokenized = tokenizer.encode_plus(input_text, padding=True, max_length=max_length) featurized_sample = {"input_ids": tokenized["input_ids"], "attention_mask": tokenized["attention_mask"], "tokens": tokenized.encodings[0].tokens, "target": sample[label_column].astype(int), "ad_id": sample["ad_id"]} if "token_type_ids" in tokenized: featurized_sample["token_type_ids"] = tokenized["token_type_ids"] return featurized_sample - Assistant
- User
after concatination how long is the lenght of tokens?
- Assistant
After concatenation, the length of the tokens will depend on the combined length of the input text and the maximum length specified. If the combined length of the input text is less than or equal to the maximum length, the length of the tokens will be the same as the combined length. However, if the combined length exceeds the maximum length, the length of the tokens will be equal to the maximum length, and the text may be truncated or split into multiple parts.
- User
can you change the code that get mean value from each chunk?
- Assistant
Yes, I can modify the code to calculate the mean value from each chunk. Here's an example of how you can modify the
sample_to_featuresfunction to calculate the mean value from each chunk of tokens:python
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.