Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
1 vote
1 answer
55 views

How to Process Data on GPU Instead of RAM for This Python Code?

I'm currently using the following code to process audio data, but it runs on the RAM. I want to offload the processing to the GPU to improve performance. my code : def prepare_dataset(batch): ...
Elena Aston's user avatar
0 votes
1 answer
95 views

ValueError: Expected input batch_size (2) to match target batch_size (4)

Here is the code for a text classification task I am doing. The issue seems to lie here. This is a multi class problem. I have 3 labels. I tried several things. I changed the format of the labels to ...
Andreea-Codrina Moldovan's user avatar
0 votes
0 answers
84 views

How do I fix "ValueError: The model did not return a loss from the inputs"?

I am writing a program in Python. What it does is to train a question-answering model, and it uses a custom-made dataset from a JSON file that I created. However, I ran into the error from the full ...
Jungle Zee's user avatar
0 votes
1 answer
157 views

During the training of the language model, an error occurs: torch.cuda.OutOfMemoryError: CUDA out of memory

During the second iteration of the finetuning of the language model, an error occurs: optimizer = AdamW(model.parameters(), lr=1e-4) scheduler = get_linear_schedule_with_warmup(optimizer, ...
Geanry Blog's user avatar
2 votes
0 answers
62 views

I have text data to perform sentiment analysis. With 3 classes I want to create embeddings and get centroids of the data. Any ideas?

I have text data to perform sentiment analysis. With three classes (-1,0,1) I would like to create embeddings and get the centroids of the data so new data can be assigned according to the centroids ...
snaikkk's user avatar
  • 21
0 votes
1 answer
358 views

Calculating similarity score in contexto.me clone

I am currently trying to clone the popular browser game contexto.me and I am having trouble with as to how to calculate the similarity score between two words (the target word and the user inputted ...
FarajSiddique's user avatar
0 votes
1 answer
713 views

Module "torchtext.data" has no attribute "Field"

I am trying to define a vocabulary with PyTorch to later input my dataset into a Neural Network. This would be the first step to create a dataset. This is the code I am using: text_field = torchtext....
gmunda's user avatar
  • 1
1 vote
1 answer
1k views

TokenClassificationChunkPipeline is throwing error: 'BatchEncoding' object is not an iterator

Following this HuggingFace Anonymisation Tutorial. Using pytorch 2.0.0 and transformers-4.28.1 Running the code as it is, I get an error over the custom pipeline: def anonymize(text): ents = pipe(...
George Petropoulos's user avatar
0 votes
1 answer
709 views

I am getting error here torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse) when I call trainer.train() function of GPT2 model

I am new to NLP and I was trying gpt2 to train on my own data. from transformers import GPT2Config, GPT2LMHeadModel, GPT2Tokenizer, TextDataset, DataCollatorForLanguageModeling, Trainer, ...
Shubhankar Kumar's user avatar
1 vote
1 answer
915 views

Why do people set label token's value that has <pad> token to -100 when Language model is pre-trained?

enter image description here Why do people set label token's value that has token to -100 when Language model is pre-trained? For example, values with pad token in the following figure, are converted ...
kimchdragon's user avatar
1 vote
1 answer
199 views

nn.Transformer src/tgt/memory masks fail to work

nn.TransformerEncoderLayer produces exactly same output with same src,no matter what src_key_padding_mask or src_mask is. Likewise,nn.TransformerDecoderLayer output is not affected by any one of ...
haoxing's user avatar
  • 11
0 votes
2 answers
541 views

Split torch tensor : max size and end of the sentence

I would like to split a tensor into several tensors with torch on Python. The tensor is the tokenization of a long text. First here is what I had done: tensor = tensor([[ 3746, 3120, 1024, ..., ...
Alex's user avatar
  • 337
0 votes
0 answers
2k views

ModuleNotFoundError: No module named 'torchdata'

How can get the training data as text (or list of texts) from PyTorch Dataset(<torchtext.data.dataset.Dataset>) Object ? Or more specifically from torchtext squad 1 or 2 the Q&a version I ...
Farah Rostom's user avatar
1 vote
1 answer
4k views

BERT training error - forward() got an unexpected keyword argument 'labels'

I'm trying to train Bert for question answering using squad. At the end I wanna use Labse for this and train it again on other language and see the score growth. As I train bert I immediately get this ...
Mateusz Pasierbek's user avatar
1 vote
0 answers
598 views

How to do text vectorization in Torch as a model layer

Is there a way to get a Torch model to do text-vectorization? In Torch, I can't find a way to do the vectorization inside the model. Every example I have found applies the vectorization inside the ...
Frank's user avatar
  • 1,196
7 votes
0 answers
602 views

Is there a way tell a trained transformer model (e.g. from hugging face) to cast to float?

I am attempting to run the T5 transformer on an M1 Mac using MPS backend: import torch import json from transformers import T5Tokenizer, T5ForConditionalGeneration, T5Config #Make sure sentencepiece ...
DrRaspberry's user avatar
5 votes
2 answers
8k views

Pytorch NLP Huggingface: model not loaded on GPU

I have this code that init a class with a model and a tokenizer from Huggingface. On Google Colab this code works fine, it loads the model on the GPU memory without problems. On Google Cloud Platform ...
Nazareno De Francesco's user avatar
0 votes
1 answer
276 views

implement do_sampling for custom GPT-NEO model

import numpy as np from transformers import GPTNeoForCausalLM, GPT2Tokenizer import coremltools as ct tokenizer = GPT2Tokenizer.from_pretrained("gpt2") sentence_fragment = "The Oceans ...
Olexander Korenyuk's user avatar
1 vote
1 answer
366 views

Using RTX3090 with Haystack

The current release of Haystack (deepset.ai) supports GPU's but it is not using a new enough CUDA support (>= 11.1) to work with my RTX3090. Can I just uninstall the current version of torch and ...
Michael Wade's user avatar
0 votes
1 answer
603 views

pyTorch: how to reset its state?

I'm using pyTorch and for some reason - after refactoring my code - it's not working anymore. The error is: File ".\api\deepmatcher\data\dataset.py", line 420, in load_cache ...
Rafaó's user avatar
  • 600
0 votes
1 answer
939 views

Fine-Tuned ALBERT Question and Answering with HuggingFace

I'm trying to create a question and answering AI, I would like it to be as accurate as possible without having to train the model myself. I can create a simple AI using the existing base models like ...
johnny 5's user avatar
  • 20.9k
1 vote
0 answers
1k views

How to load a fine tuned model from BertForSequenceClassification and use it to tokenize a sentence?

I'm following this tutorial (https://mccormickml.com/2019/07/22/BERT-fine-tuning/#a1-saving--loading-fine-tuned-model) in order to fine-tune a BertForSequenceClassification. After I train the model, I ...
Lucas Penna's user avatar
1 vote
1 answer
186 views

Heroku keeps installing the torch package which I uploaded before

I am deploying to heroku but exceeded slug size of 500 mb. remote: Collecting torch>=1.0.0 remote: Downloading torch-1.7.1-cp36-cp36m-manylinux1_x86_64.whl (776.8 MB) Torch keeps ...
ant_22's user avatar
  • 11
1 vote
1 answer
3k views

Train n% last layers of BERT in Pytorch using HuggingFace Library (train Last 5 BERTLAYER out of 12 .)

Bert has an Architecture something like encoder -> 12 BertLayer -> Pooling. I want to train the last 40% layers of Bert Model. I can freeze all the layers as: # freeze parameters bert = ...
Deshwal's user avatar
  • 4,132
1 vote
1 answer
3k views

How to get reproducible results of T5 transformer model

I'm trying to get reproducible results of T5 transformer model: import torch from transformers import T5ForConditionalGeneration,T5Tokenizer def set_seed(seed): torch.manual_seed(seed) if torch....
Fluxy's user avatar
  • 2,978
2 votes
1 answer
618 views

Why W_q matrix in torch.nn.MultiheadAttention is quadratic

I am trying to implement nn.MultiheadAttention in my network. According to the docs, embed_dim  – total dimension of the model. However, according to the source file, embed_dim must be divisible by ...
Akim Tsvigun's user avatar
-1 votes
1 answer
188 views

How to use batch to run RNN model with texts that have different length in each row?

I want to use torch.nn.utils.rnn.pack_padded_sequence in pytorch to deal with this problem, But I dont kown how to get torch variable when it has different size in the last dimension? torch.nn.utils....
wa007's user avatar
  • 125
0 votes
1 answer
1k views

Huggingface Bert: Output Printing

I'm new to coding, and could use guidance as to why it is printing oddly like it is. While this is related to NLP, I believe this error could most likely be explained by somebody who has greater ...
Johnny's user avatar
  • 125
0 votes
1 answer
333 views

Visualize text classes in a scatter-plot

I am looking for ways to investigate in my train data 'modellability' and check if the classes are well distinguished in terms of vocabulary... etc. I am a bit embarrassed but I was wondering if it ...
monti's user avatar
  • 794
1 vote
0 answers
1k views

Distill bert and svm for text classification

I am using DistillBert from hugging face to get the vector embedding of the words. The output for the example in hugging face will be a torch tensor with three dimensions. how can I feed these ...
sima's user avatar
  • 21
2 votes
0 answers
112 views

pytorch TabularDataset: can't load a large file?

I have this training set of about 1.4 GB, but I can't load it in a TabularDataset. >>> REF = data.Field(lower=True, tokenize=tokenize_char, init_token='<sos>',eos_token='<eos>') &...
Yingqiang Gao's user avatar
1 vote
0 answers
1k views

how do you generate an ONNX representation of a pytorch bert pretrained neural network?

I am trying to generate an ONNX file for the pytorch-pretrained-bert run_classifier.py example. In this case, I'm running it with the following parameters as per the main README.md: export GLUE_DIR=...
James Fremen's user avatar
  • 2,270
0 votes
1 answer
569 views

Unable to use bidaf model without using 'cuda_device' : bidafPredictor._model.forward_on_instance(inst, cuda_device=-1)

I am trying to use bidaf question answer model source from : https://github.com/allenai/bi-att-flow This class is created to use the library provided by https://github.com/allenai. ## REQUIRES ...
parinaya-007's user avatar