huggingface-transformers

tokenizer.save_pretrained TypeError: Object of type property is not JSON serializable

tokenizer.save_pretrained TypeError: Object of type property is not JSON serializable Question: I am trying to save the GPT2 tokenizer as follows: from transformers import GPT2Tokenizer, GPT2LMHeadModel tokenizer = GPT2Tokenizer.from_pretrained("gpt2") tokenizer.pad_token = GPT2Tokenizer.eos_token dataset_file = "x.csv" df = pd.read_csv(dataset_file, sep=",") input_ids = tokenizer.batch_encode_plus(list(df["x"]), max_length=1024,padding=’max_length’,truncation=True)["input_ids"] # saving the tokenizer tokenizer.save_pretrained("tokenfile") I am getting the following error: TypeError: …

Total answers: 1

How do you train Huggingface Maskformer for instance segmentation?

How do you train Huggingface Maskformer for instance segmentation? Question: I can see an example to train for semantic segmentation but I’m unclear how to fine tune a model for instance segmentation. Specifically how to calculate the loss function assuming the data is in COCO format? Asked By: nickponline || Source Answers: I found a …

Total answers: 1

Pytorch complaining about input and label batch size mismatch

Pytorch complaining about input and label batch size mismatch Question: I am using Huggingface to implement a BERT model using BertForSequenceClassification.from_pretrained(). The model is trying to predict 1 of 24 classes. I am using a batch size of 32 and a sequence length of 66. When I try to call the model in training, I …

Total answers: 1

Train T5/BART to convert a string into multiple strings

Train T5/BART to convert a string into multiple strings Question: Is it possible to train a seq2seq model like T5 or BART to convert a string into a list of strings? On my first attempt, the tokenizer complained that my 2D list of labels isn’t the correct data type: File "/home/matt/miniconda3/envs/nlp/lib/python3.10/site-packages/transformers/tokenization_utils_fast.py", line 429, in _batch_encode_plus …

Total answers: 1

TypeError: unsupported operand type(s) for /: 'SequenceClassifierOutput' and 'int'

TypeError: unsupported operand type(s) for /: 'SequenceClassifierOutput' and 'int' Question: I am using hugginface library to train a bert model on classification problem. model = BertForSequenceClassification.from_pretrained(‘bert-base-uncased’, num_labels=10) def training_step(self, batch, batch_nb): sequence, label = batch input_ids, attention_mask, labels = self.prepare_batch(sequence=sequence, label=label) loss = self.model(input_ids=input_ids, attention_mask=attention_mask, labels=labels) tensorboard_logs = {‘train_loss’: loss} I am getting the following …

Total answers: 1

How to split input text into equal size of tokens, not character length, and then concatenate the summarization results for Hugging Face transformers

How to split input text into equal size of tokens, not character length, and then concatenate the summarization results for Hugging Face transformers Question: I am using the below methodology to summarize longer than 1024 token size long texts. Current method splits the text by half. I took this from another user’s post and modified …

Total answers: 1

How to enable GPU for SetFit?

How to enable GPU for SetFit? Question: I am following this tutorial for SetFit: https://www.philschmid.de/getting-started-setfit When the training is running, it is using my CPU instead of my GPU. Is there a way I can enable it? Here is the main part of the code: from setfit import SetFitModel, SetFitTrainer from sentence_transformers.losses import CosineSimilarityLoss # …

Total answers: 1

How to fine-tune gpt-j using Huggingface Trainer

How to fine-tune gpt-j using Huggingface Trainer Question: I’m attempting to fine-tune gpt-j using the huggingface trainer and failing miserably. I followed the example that references bert, but of course, the gpt-j model isn’t exactly like the bert model. The error indicates that the model isn’t producing a loss, which is great, except that I …

Total answers: 2

The expanded size of the tensor (1011) must match the existing size (512) at non-singleton dimension 1

The expanded size of the tensor (1011) must match the existing size (512) at non-singleton dimension 1 Question: I have a trained a LayoutLMv2 model from huggingface and when I try to inference it on a single image, it gives the runtime error. The code for this is below: query = ‘/Users/vaihabsaxena/Desktop/Newfolder/labeled/Others/Two.pdf26.png’ image = Image.open(query).convert("RGB") …

Total answers: 1