category
stringclasses
107 values
title
stringlengths
15
179
question_link
stringlengths
59
147
question_body
stringlengths
53
33.8k
answer_html
stringlengths
0
28.8k
__index_level_0__
int64
0
1.58k
T5 model
Flan T5 - How to give the correct prompt/question?
https://stackoverflow.com/questions/75203036/flan-t5-how-to-give-the-correct-prompt-question
<p>Giving the right kind of prompt to Flan T5 Language model in order to get the correct/accurate responses for a chatbot/option matching use case.</p> <p>I am trying to use a Flan T5 model for the following task. Given a chatbot that presents the user with a list of options, the model has to do semantic option matchin...
<p>A recent paper goes into detail about how the Flan Collection was created (&quot;<a href="https://arxiv.org/abs/2301.13688" rel="noreferrer">The Flan Collection: Designing Data and Methods for Effective Instruction Tuning</a>&quot;) and points to a GitHub repo with <a href="https://github.com/google-research/FLAN/bl...
34
T5 model
How to use huggingface T5 model to test translation task?
https://stackoverflow.com/questions/60513592/how-to-use-huggingface-t5-model-to-test-translation-task
<p>I see there exits two configs of the T5model - <strong>T5Model</strong> and <strong>TFT5WithLMHeadModel</strong>. I want to test this for translation tasks (eg. en-de) as they have shown in the google's original repo. Is there a way I can use this model from hugging face to test out translation tasks. I did not see ...
<p>You can use <em>T5ForConditionalGeneration</em> to translate your text...</p> <pre><code>!pip install transformers from transformers import T5Tokenizer, T5ForConditionalGeneration tokenizer = T5Tokenizer.from_pretrained('t5-small') model = T5ForConditionalGeneration.from_pretrained('t5-small', return_dict=True) ...
35
T5 model
How to run inference for T5 tensorrt model deployed on nvidia triton?
https://stackoverflow.com/questions/71911630/how-to-run-inference-for-t5-tensorrt-model-deployed-on-nvidia-triton
<p>I have deployed T5 tensorrt model on nvidia triton server and below is the config.pbtxt file, but facing problem while inferencing the model using triton client.</p> <p>As per the config.pbtxt file there should be 4 inputs to the tensorrt model along with the decoder ids. But how can we send decoder as input to the ...
<p>You have several examples in the <a href="https://github.com/triton-inference-server/client/tree/main" rel="nofollow noreferrer">NVIDIA Triton Client</a> repository. However, it might be the case, if your use case is too complex, that you might need the Python backend instead of the Torch one.</p> <p>You initialize ...
36
T5 model
I am trying to convert a flan-t5 pytorch model to GGUF format
https://stackoverflow.com/questions/77200600/i-am-trying-to-convert-a-flan-t5-pytorch-model-to-gguf-format
<p>I have tried to convert the model using the llama.cpp convert.py following the colab note <a href="https://colab.research.google.com/github/TrelisResearch/gguf-quantization/blob/main/HuggingFace_to_GGUF.ipynb#scrollTo=CmT3xkz0GHJN" rel="nofollow noreferrer">HERE</a>.</p> <pre><code> model = AutoModelForSeq2SeqLM.fro...
<p>This can be achieved using the candle framework resources to convert encoder-decoder models. <a href="https://huggingface.co/lmz/candle-quantized-t5/tree/main" rel="nofollow noreferrer">Here</a> are the GGUF conversions of T5 Models</p>
37
T5 model
Can we convert dynamic DNN model to TorchScript?
https://stackoverflow.com/questions/76473823/can-we-convert-dynamic-dnn-model-to-torchscript
<p>all.</p> <p>I'm trying to convert SwitchTransformer model to TorchScript. (SwitchTransformer model is MoE DNN based on Google T5 model.)</p> <p>When converting both T5 and SwitchTransforemer, there's no error for T5 but I got following error for SwitchTransformer.</p> <pre><code>/root/HuggingFace/.HF/lib/python3.8/s...
38
T5 model
Fine-tune T5 pre-trained model on a specific domain for question answering
https://stackoverflow.com/questions/75459693/fine-tune-t5-pre-trained-model-on-a-specific-domain-for-question-answering
<p>I need to build a question-answering system on a specific domain of Finance, I have documents data containing all the information about the field,</p> <p>Can I fine-tune T5 pre-trained model (large) unsupervised training on the documents so it can answer related questions based on my documents corpus?<br /> The docu...
<p>What I found is that it is not really feasible to fine-tune T5 LLM word embeddings, you can only use context or fine-tune the model on a dataset of QA, but not retrain the model on a specific domain like finance which was my case,<br /> I ended up building the QA system using Haystack which is an open-source library...
39
T5 model
Sentence embedding using T5
https://stackoverflow.com/questions/64579258/sentence-embedding-using-t5
<p>I would like to use state-of-the-art LM T5 to get sentence embedding vector. I found this repository <a href="https://github.com/UKPLab/sentence-transformers" rel="noreferrer">https://github.com/UKPLab/sentence-transformers</a> As I know, in BERT I should take the first token as [CLS] token, and it will be the sente...
<p>In order to obtain the sentence embedding from the T5, you need to take the take the <code>last_hidden_state</code> from the T5 encoder output:</p> <pre><code>model.encoder(input_ids=s, attention_mask=attn, return_dict=True) pooled_sentence = output.last_hidden_state # shape is [batch_size, seq_len, hidden_size] # p...
40
T5 model
ValueError: You have to specify either decoder_input_ids or decoder_inputs_embeds
https://stackoverflow.com/questions/65140400/valueerror-you-have-to-specify-either-decoder-input-ids-or-decoder-inputs-embed
<p>Trying to convert a <code>question-generation</code> t5 model to <code>torchscript</code> <a href="http://%5Bmodel%5D(https://huggingface.co/transformers/torchscript.html#torchscript)." rel="noreferrer">model</a>, while doing that Running into this error</p> <p><strong>ValueError: You have to specify either decoder_...
<p><strong>Update</strong>: refer to <a href="https://stackoverflow.com/a/66117248/13273054">this</a> answer and if you are exporting <code>t5</code> to <code>onnx</code>, it can be done easily using the <a href="https://github.com/Ki6an/fastT5" rel="nofollow noreferrer"><code>fastT5</code></a> library.</p> <p>I figure...
41
T5 model
How to finetune the huggingface T5 model on custom data?
https://stackoverflow.com/questions/64818504/how-to-finetune-the-huggingface-t5-model-on-custom-data
<p>I have a small text dataset for translation which I want to fine-tune with <code>t5-small</code>, Here is the code which I am trying to use to finetune.</p> <pre><code>import numpy as np import tensorflow as tf from transformers import TFT5ForConditionalGeneration, T5Tokenizer model = TFT5ForConditionalGeneration.f...
42
T5 model
Is it valid to evaluate a flan-t5 model on sequences longer than it&#39;s max_length of 2048 tokens (assuming I have enough memory)?
https://stackoverflow.com/questions/76495456/is-it-valid-to-evaluate-a-flan-t5-model-on-sequences-longer-than-its-max-length
<p>I am evaluating the different flan-t5 models with few-shot chain of thought prompts which can go over the 2048 maximum token length. I am under the impression that because T5 uses relative position encoding, that it would be valid (make sense) to do zero shot on sequences longer than 2048, provided that I can handle...
43
T5 model
Why my trained t5-small model generate a mess after I saved and loaded the checkpoint?
https://stackoverflow.com/questions/79205866/why-my-trained-t5-small-model-generate-a-mess-after-i-saved-and-loaded-the-check
<p>I was distilling my student model (base model t5-small) based on a fine-tuned T5-xxl. Here is the config</p> <pre><code>student_model = AutoModelForSeq2SeqLM.from_pretrained( args.student_model_name_or_path, torch_dtype=torch.float32, device_map=&quot;auto&quot;, cache_dir=args.cache_dir, quanti...
44
T5 model
T5 Encoder model output all zeros?
https://stackoverflow.com/questions/67455305/t5-encoder-model-output-all-zeros
<p>I am trying out a project where I use the T5EncoderModel from HuggingFace in order to obtain hidden representations of my input sentences. I have 100K sentences which I tokenize and pad as follows:</p> <pre><code> for sentence in dataset[original]: sentence = tokenizer(sentence, max_length=40, padding='max_l...
45
T5 model
How to denoise text using T5?
https://stackoverflow.com/questions/76186015/how-to-denoise-text-using-t5
<p>I'm trying to denoise text using a T5 model following <a href="https://huggingface.co/docs/transformers/v4.28.1/en/model_doc/t5#transformers.T5ForConditionalGeneration" rel="nofollow noreferrer">the Huggingface doc:</a></p> <pre><code>from transformers import T5Tokenizer, T5ForConditionalGeneration tokenizer = T5Tok...
<p>In the in <a href="https://huggingface.co/docs/transformers/v4.29.1/model_doc/t5#inference" rel="nofollow noreferrer">docs for T5 (§ Inference)</a> there is an example of what you're looking for.</p> <pre class="lang-py prettyprint-override"><code>from transformers import T5Tokenizer, T5ForConditionalGeneration tok...
46
T5 model
use_cuda is set True even though it was specified as False T5
https://stackoverflow.com/questions/74138756/use-cuda-is-set-true-even-though-it-was-specified-as-false-t5
<p>I am trying to train a T5 model using <code>simpletransformers</code>. Here is my code:</p> <pre><code>from simpletransformers.t5 import T5Model model_args = { &quot;max_seq_length&quot;: MAX_LEN, &quot;train_batch_size&quot;: 8, &quot;eval_batch_size&quot;: 8, &quot;num_train_epochs&quot;: 1, &q...
<p>You need to pass in the arg <code>use_cuda</code> to the call to the <code>T5Model</code> constructor, not in your <code>model_args</code> dict.</p> <pre class="lang-py prettyprint-override"><code>from simpletransformers.t5 import T5Model model_args = {...} model = T5Model('t5', 't5-base', args=model_args, use_cud...
47
T5 model
How to get the logits for the T5 model when using the `generate` method for inference?
https://stackoverflow.com/questions/73781510/how-to-get-the-logits-for-the-t5-model-when-using-the-generate-method-for-infe
<p>I'm currently using HuggingFace's T5 implementation for text generation purposes. More specifically, I'm using the <code>T5ForConditionalGeneration</code> to solve a text classification problem as generation.</p> <p>The model's performance is overall very satisfactory after training, but what I am wondering is how I...
<p>I was struggling with this because I wasn't familiar with how the Transformers library works, but after looking at the source code all you have to do is set the arguments <code>output_scores</code> and <code>return_dict_in_generate</code> to <code>True</code>.</p> <p>For more information, take a look at the method <...
48
T5 model
How to use forward() method instead of model.generate() for T5 model
https://stackoverflow.com/questions/67328345/how-to-use-forward-method-instead-of-model-generate-for-t5-model
<p>For my use case, I need to use the model.forward() instead of the model.generate() method i.e instead of the below code</p> <pre><code>outs = model.model.generate(input_ids=batch['source_ids'], attention_mask=batch['source_mask'], output_scores=True, ...
<p>The two methods do something completely different.</p> <p>Calling the model (which means the <code>forward</code> method) uses the <code>labels</code> for teacher forcing. This means inputs to the decoder are the <code>labels</code> shifted by one (see <a href="https://huggingface.co/transformers/model_doc/t5.html#t...
49
T5 model
Pytorch T5 training loss not changing
https://stackoverflow.com/questions/76337204/pytorch-t5-training-loss-not-changing
<p>I am trying to fine tune a T5 model for more accurate summarization, but my loss is very high and does not change with each epoch. I have tried increasing the learning rate, but the model still does not train. It seems like there is some issue with the code since the loss doesn't change at all. My input texts are ve...
<p>Based on your <a href="https://stackoverflow.com/questions/76320189/pytorch-calculate-loss-with-smaller-target-tensor">other question on this problem</a>, where you mentioned that you're new to <code>PyTorch</code>, my answer reflects the general approach I personally use when I need to work with a new machine-learn...
50
T5 model
Speeding-up inference of T5-like model
https://stackoverflow.com/questions/71210238/speeding-up-inference-of-t5-like-model
<p>I am currently using a model called T0pp (<a href="https://huggingface.co/bigscience/T0pp" rel="nofollow noreferrer">https://huggingface.co/bigscience/T0pp</a>) in production and would like to speed up inference.</p> <p>I am running the following code on an on-demand EC2 g4dn.12xlarge instance (4 Nvidia T4 GPUs):</p...
<p>Maybe you could try <a href="https://docs.openvino.ai/latest/openvino_docs_install_guides_overview.html" rel="nofollow noreferrer">OpenVINO</a>? It allows you to convert your model into Intermediate Representation (IR) and then run on the CPU with the FP16 support. OpenVINO is optimized for Intel hardware but it sho...
51
T5 model
What do the `&lt;extra_idx&gt;` tokens in T5 mean?
https://stackoverflow.com/questions/73740232/what-do-the-extra-idx-tokens-in-t5-mean
<p>I'm using the mT5 model from HuggingFace Transformers to perform some conditional generation and apply it to text classification.</p> <p>I noticed that whatever the T5 model generates (and before it's trained sufficiently) it usually generates special tokens that look like <code>&lt;extra_id0&gt;</code> or <code>&lt...
<p>The &lt;extra_id_0&gt; and &lt;extra_id_1&gt; tokens are part of the T5 tokenizer's extra_ids vocabulary, used as sentinel tokens for masking parts of the input that the model needs to predict. These tokens are indexed from the end of the vocabulary to the beginning. You can specify the number of masked tokens to us...
52
T5 model
Getting logits from T5 Hugging Face model using forward() method without labels
https://stackoverflow.com/questions/73411215/getting-logits-from-t5-hugging-face-model-using-forward-method-without-labels
<p>For my use case, I need to obtain the logits from T5's forward() method without inputting labels. I know that forward() and .generate() are different (<a href="https://stackoverflow.com/questions/67328345/how-to-use-forward-method-instead-of-model-generate-for-t5-model">see here</a>). I have also seen <a href="https...
<p>Yes, you can do it. Huggingface library does not requires labels strictly as input to the forward method. See for example here for Bert: <a href="https://github.com/huggingface/transformers/blob/v4.21.1/src/transformers/models/bert/modeling_bert.py#L1079" rel="nofollow noreferrer">https://github.com/huggingface/tran...
53
T5 model
why the output of T5 model contains &lt;extra_id_0&gt; ,.... when the input is not mask
https://stackoverflow.com/questions/76731327/why-the-output-of-t5-model-contains-extra-id-0-when-the-input-is-not-mas
<p>I fintuned mT5 with new dataset for summarization task.<br /> In the inference phase, mT5 generate outputs contains &lt;extra_id_1&gt;, ... when the input is not mask.</p> <p>I use the blow code to encode the input:</p> <p>`tokenized_inputs = self.tokenizer.batch_encode_plus(<br /> [line], max_length=self.max_len,<...
54
T5 model
How to load model after saving only with torch.save(model)?
https://stackoverflow.com/questions/73034501/how-to-load-model-after-saving-only-with-torch-savemodel
<p>I just trained a model based on the T5 network, but I managed to save it only with</p> <pre class="lang-py prettyprint-override"><code>torch.save(model, 'trained_model') </code></pre> <p>Which saved the model in a single <code>trained_model</code> file.</p> <p>When I now try to load it with</p> <pre class="lang-py p...
<p>try this for saving the model</p> <pre><code>torch.save(model.state_dict(), PATH) </code></pre> <p>and for load that model again</p> <pre><code>model = TheModelClass(*args, **kwargs) model.load_state_dict(torch.load(PATH)) model.eval() </code></pre> <p>there other way to do that you can find in <a href="https://pyto...
55
T5 model
How to freeze a huggingface model?
https://stackoverflow.com/questions/70352825/how-to-freeze-a-huggingface-model
<p>I use</p> <pre><code> for p in model.parameters(): p.requires_grad = False </code></pre> <p>to freeze a T5 model (t5-small), but when I print parameters that require grad, there is still one parameter with the size <code>32121x512</code>. What is this? Is it the embeddings matrix? Should I freeze...
<p>It seems I called <code>model.resize_token_embeddings(len(tokenizer))</code> after freezing parameters, and it can reset the embeddings require_grad to True</p>
56
T5 model
How to push NLP model trained with pytorch in hugging face?
https://stackoverflow.com/questions/69585470/how-to-push-nlp-model-trained-with-pytorch-in-hugging-face
<p>I trained fine tune T5 model with my dataset.</p> <p>Here is my model class</p> <pre><code>class QA_model(pl.LightningModule): def __init__(self): super().__init__() self.model=T5ForConditionalGeneration.from_pretrained(model_t5,return_dict=True) def forward(self,input_ids, attention_mask,labels=None):...
57
T5 model
T5 fine tuned model outputs &lt;unk&gt; instead of curly braces and other special characters
https://stackoverflow.com/questions/75851029/t5-fine-tuned-model-outputs-unk-instead-of-curly-braces-and-other-special-char
<p>First of I'll start with saying that I'm a beginner when it comes to machine learning as a whole and transformers so my apologies if it's a dumb question. I've been fine tuning t5 for the task of generating mongodb queries, but I was met with this strange output that doesn't look like as the intended one.</p> <pre><...
<p>After some research I've found a solution. T5 tokenizer vocab was missing a few characters like curly braces and others, so I used the following to add them.</p> <pre><code>from transformers import AutoModel new_words = ['{', '}'] model = AutoModel.from_pretrained(&quot;t5-base&quot;) tokenizer.add_tokens(new_wo...
58
T5 model
How to load a saved model for a Hoggingface T5 model where the tokenizer was extended in the training phase?
https://stackoverflow.com/questions/75075829/how-to-load-a-saved-model-for-a-hoggingface-t5-model-where-the-tokenizer-was-ext
<p>I use the following code to load the saved model:</p> <pre><code> config = T5Config.from_pretrained( model_name_or_path, cache_dir=model_args.cache_dir, revision=model_args.model_revision, use_auth_token=True if model_args.use_auth_token else None, ) config.train_task_adapters...
<p>Usually you don't encounter any problems when loading the model for which you've added some extra tokens during the training. In my case, it was the <code>pad_to_multiple_of</code> parameter that caused the trouble. It is claimed to do some Nvidia magic for a more efficient utilization of modern GPUs, so I used it w...
59
T5 model
flan-t5-xxl: ValueError: Need either a `state_dict` or a `save_folder` containing offloaded weights
https://stackoverflow.com/questions/76617863/flan-t5-xxl-valueerror-need-either-a-state-dict-or-a-save-folder-containin
<p>I tried to run flan-t5-xxx model from Hugging Face both in my Mac M1 and Google Colab, both have the same error:</p> <p><code>ValueError: Need either a state_dict or a save_folder containing offloaded weights.</code></p> <p>The code from Model Card:</p> <pre><code>from transformers import T5Tokenizer, T5ForCondition...
<p>For who need:</p> <p>Create a folder (name save_folder for example). Then update:</p> <pre><code>model = T5ForConditionalGeneration.from_pretrained(&quot;google/flan-t5-xxl&quot;, device_map=&quot;auto&quot;) </code></pre> <p>to</p> <pre><code>model = T5ForConditionalGeneration.from_pretrained(&quot;google/flan-t5-x...
60
T5 model
Can I add configuration of &#39;dropout_rate&#39; to Seq2SeqTrainer?
https://stackoverflow.com/questions/76281106/can-i-add-configuration-of-dropout-rate-to-seq2seqtrainer
<p>I'am trying to train T5 model using Seq2SeqTrainer. I found out that the Config of T5 model is like below.</p> <pre><code>T5Config { &quot;_name_or_path&quot;: &quot;allenai/tk-instruct-base-def-pos&quot;, &quot;architectures&quot;: [ &quot;T5ForConditionalGeneration&quot; ], &quot;attention_probs_dropou...
61
T5 model
Size Mismatch in MultiModal Feedback Model Using T5 + Audio/Visual Features - The size of tensor a (48) must match the size of tensor b (4) with T5
https://stackoverflow.com/questions/79588847/size-mismatch-in-multimodal-feedback-model-using-t5-audio-visual-features-th
<p>I’m working on a multimodal model that combines audio and visual features with a T5-based encoder for a feedback generation task. However, I’m facing an issue with batch size mismatch between the projected audio/visual features and the encoder outputs, which leads to the error:</p> <p>❌ Error in batch 1: The size of...
62
T5 model
AttributeError: Adam object has no attribute &#39;_decayed_lr&#39; when fine-tuning T5
https://stackoverflow.com/questions/76987203/attributeerror-adam-object-has-no-attribute-decayed-lr-when-fine-tuning-t5
<p>I am fine-tuning T5 LLM, with the model based on this Colab notebook from Google: <a href="https://colab.research.google.com/github/snapthat/TF-T5-text-to-text/blob/master/snapthatT5/notebooks/TF-T5-Datasets%20Training.ipynb#scrollTo=dEutWnhiWRAq" rel="nofollow noreferrer">TF-T5- Training.ipynb</a>. My current model...
63
T5 model
Low score and wrong answer for Flan-T5-XXL &quot;question-answering&quot; task
https://stackoverflow.com/questions/76963864/low-score-and-wrong-answer-for-flan-t5-xxl-question-answering-task
<p>I'm trying to run Flan-T5-XXL model for a &quot;question-answering&quot; task. Here's how I loaded and executed the model:</p> <pre><code>model_id = &quot;~/Downloads/test_LLM/flan-t5-xxl&quot; tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForQuestionAnswering.from_pretrained(model_id, return_...
<p><strong>Pre/Script:</strong> This is more of a science experiment design or product development question than a programming question, so most probably someone will flag to close this question on Stackoverflow eventually. But here's an attempt to answer.</p> <h1>In Short</h1> <p>There is a couple of things to conside...
64
T5 model
Cannot use SparkNLP pre-trained T5Transformer, executor fails with error &quot;No Operation named [encoder_input_ids] in the Graph&quot;
https://stackoverflow.com/questions/66207669/cannot-use-sparknlp-pre-trained-t5transformer-executor-fails-with-error-no-ope
<p>Downloaded T5-small model from SparkNLP website, and using this code (almost entirely from the examples):</p> <pre><code> import com.johnsnowlabs.nlp.SparkNLP import com.johnsnowlabs.nlp.annotators.seq2seq.T5Transformer import org.apache.spark.sql.SparkSession val spark = SparkSession.builder() ...
<p>The offline model of T5 - <code>t5_base_en_2.7.1_2.4_1610133506835</code> - was trained on SparkNLP 2.7.1, and there was a <a href="https://github.com/JohnSnowLabs/spark-nlp/commit/3fead96ec9274ddf3b79fb853afa0d03da4ed393#diff-761d0a1c998acc94c5759dee89ee674e82f4b6e02f7a9b8c2f64dfd272482d2f" rel="nofollow noreferre...
65
T5 model
git push error:fatal: unable to access .....Port number ended with &#39;a&#39;
https://stackoverflow.com/questions/69604479/git-push-errorfatal-unable-to-access-port-number-ended-with-a
<p>I finetuned the t5 model and I want to upload it on my hugging face library. I have my directory, where I save tokenizer and model.</p> <pre><code>tokenizer.save_pretrained('my-t5-qa-legal') trained_model.model.save_pretrained('my-t5-qa-legal') </code></pre> <p>Here are files in my directory:</p> <pre><code>!ls con...
66
T5 model
TypeError: _get_dataset_for_single_task() got an unexpected keyword argument &#39;sequence_length&#39; #790
https://stackoverflow.com/questions/67027987/typeerror-get-dataset-for-single-task-got-an-unexpected-keyword-argument-se
<p>I got the following error in the evaluation of a <a href="https://github.com/google-research/text-to-text-transfer-transformer" rel="nofollow noreferrer">t5</a> model:</p> <pre><code> model.batch_size = train_batch_size * 4 model.eval( mixture_or_task_name=&quot;trivia_all&quot;, checkpoint_steps=-1 #&quot;a...
<p>I had installed <code>t5 v0.6.0</code>, which wasn't the newest version. When I installed v0.9.0, the problem was resolved.</p> <p><code>pip install t5==0.9.0</code></p>
67
T5 model
why does huggingface t5 tokenizer ignore some of the whitespaces?
https://stackoverflow.com/questions/72214408/why-does-huggingface-t5-tokenizer-ignore-some-of-the-whitespaces
<p>I am using T5 model and tokenizer for a downstream task. I want to add certain whitespaces to the tokenizer like line ending <code>(\t)</code> and tab <code>(\t)</code>. Adding these tokens work but somehow the tokenizer always ignores the second whitespace. So, it tokenizes the sequence <code>“\n\n”</code> as a sin...
<p>The behaviour is explained by how the <code>tokenize</code> method in <code>T5Tokenizer</code> strips tokens by default. What one can do is adding the token '<code>\n</code>' as a special token to the tokenizer. Because the special tokens are never seperated, it works as expected.</p> <p>It is a bit hacky but seems ...
68
T5 model
How to use Flan-T5 with LoRA on multi gpu system?
https://stackoverflow.com/questions/79135659/how-to-use-flan-t5-with-lora-on-multi-gpu-system
<p>When using Huggingface with 'google/flan-t5-base' model, I get the error:</p> <pre><code>RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cuda:1! (when checking argument for argument index in method wrapper__index_select) </code></pre> <p>I've found in the trans...
69
T5 model
Why did my fine-tuning T5-Base Model for a sequence-to-sequence task has short incomplete generation?
https://stackoverflow.com/questions/78448914/why-did-my-fine-tuning-t5-base-model-for-a-sequence-to-sequence-task-has-short-i
<p>I am trying to fine-tune a <code>t5-base</code> model for creating appropriate question against a compliance item. Compliance iteams are paragraph of texts and my question are in the past format of them. I have trained the model, saved it and loaded it back for future usecases.</p> <p>The problem is when I am trying...
<p>Because of:</p> <pre><code>labels = tokenizer(targets, max_length=32, padding=&quot;max_length&quot;, truncation=True) </code></pre> <p>Most probably your model has learnt to just output/generate outputs that are ~32 tokens.</p> <p>Try:</p> <pre><code>labels = tokenizer(targets, max_length=512, padding=&quot;max_len...
70
T5 model
Formatting a numbered list into a cohesive prose paragraph using Hugging Face Inference API
https://stackoverflow.com/questions/79111263/formatting-a-numbered-list-into-a-cohesive-prose-paragraph-using-hugging-face-in
<p>I am playing with Hugging Face Inference API and I am trying to convert a numbered list into a cohesive prose paragraph. I have tried multiple models but I am not able to get things working.</p> <p>I have tried GPT-2, BLOOM and T5 models, but in each case I am failing to get the prose paragraph output that I am seek...
71
T5 model
problem for change batch size in my model
https://stackoverflow.com/questions/74652127/problem-for-change-batch-size-in-my-model
<p>When I train my model(my model is a transformer that its input is featured extracted from T5 model and Vit ) I have problem for set batch_size more than 2 number</p> <pre><code>number of image is 25000 for training. GPU is GTX 3090(24 gpu ram). 24 core multithreading CPU. number of total parameter =363M seq_len=512...
<p>The problem is as stated. You are running out of GPU memory. If you want to increase batch size and you are using pytorch lightning, try to use half-precision to consume less memory. <a href="https://pytorch-lightning.readthedocs.io/en/latest/common/precision_basic.html" rel="nofollow noreferrer">https://pytorch-lig...
72
T5 model
How to run .py directly in a python package?
https://stackoverflow.com/questions/70421506/how-to-run-py-directly-in-a-python-package
<p>I am working on transformer and I am interested in one of the models and would like to run the source code.</p> <p>For example, in the T5 model file, such import appears.</p> <pre><code>from ...activations import ACT2FN from ...file_utils import ( DUMMY_INPUTS, DUMMY_MASK, add_start_docstrings, add_start_docstrings_...
73
T5 model
fastchat-t5-3b-v1.0 gives truncated /incomplete answers
https://stackoverflow.com/questions/76692329/fastchat-t5-3b-v1-0-gives-truncated-incomplete-answers
<p>I have used following embeddings:</p> <ol> <li>sentence-transformers/all-mpnet-base-v2</li> <li>hkunlp/instructor-xl</li> </ol> <p>to get embedding</p> <pre><code>def getEmbedding(): device = &quot;cuda&quot; if torch.cuda.is_available() else &quot;cpu&quot; return HuggingFaceEmbeddings(model_name=&q...
74
T5 model
Get accelerate package to log test results with huggingface Trainer
https://stackoverflow.com/questions/77758645/get-accelerate-package-to-log-test-results-with-huggingface-trainer
<p>I am fine-tuning a T5 model on a specific dataset and my code looks like this:</p> <pre class="lang-py prettyprint-override"><code>accelerator = Accelerator(log_with='wandb') tokenizer = T5Tokenizer.from_pretrained('t5-base') model = T5ForConditionalGeneration.from_pretrained('t5-base') accelerator.init_trackers( p...
<p>Unfortunately, Evaluation and Prediction metrics are not logged automatically like they do for Training on <code>wandb</code>. But there are ways to push them on <code>wandb</code>.</p> <h4>Solution 01</h4> <p>You can log evaluation and prediction metrics manually, after each phases:</p> <pre><code># After evaluati...
75
T5 model
what is the issue when i tried to add a pretuned t5 model to the project from github
https://stackoverflow.com/questions/78298468/what-is-the-issue-when-i-tried-to-add-a-pretuned-t5-model-to-the-project-from-gi
<p>I git-cloned a <a href="https://github.com/farazkh80/SearchEngine" rel="nofollow noreferrer">project</a> and did all the installation. The website also launched. But I think I couldn't connect to the two files (<code>t5-base-full-seeded.ckpt</code> and <code>t5-small-full-seeded.ckpt</code>) because the project is n...
76
T5 model
How many and which layers to Freeze while using Transfer Learning?
https://stackoverflow.com/questions/76827306/how-many-and-which-layers-to-freeze-while-using-transfer-learning
<p>I am fine tuning the T5 model for QA task (NLP).</p> <p>I would like to use transfer learning, to see if I can get better results.</p> <p>Initially, I used the model like:</p> <pre><code>class QAModel(pl.LightningModule): def __init__(self): super().__init__() self.model = T5ForConditionalGeneration.from_p...
77
T5 model
Conversational Bot with Flan-T5
https://stackoverflow.com/questions/75913490/conversational-bot-with-flan-t5
<p>I am building a chat bot using flan-T5 model. The bot has a text window where one can give instructions like:</p> <ul> <li>Summarize this for me &quot;big text goes here&quot;</li> </ul> <p>Or, one might dump the text first in the chat window and then say</p> <ul> <li>Summarize the above text (or something similar t...
78
T5 model
ModuleNotFoundError: No module named &#39;gin.tf&#39;,pip install gin-config==0.1.1 not work
https://stackoverflow.com/questions/75971192/modulenotfounderror-no-module-named-gin-tf-pip-install-gin-config-0-1-1-not
<p>I downloaded the T5 model .py file(text-to-text-transfer-transformer) on the official website.</p> <p>when i run the mtf_model.py,I found the code:</p> <pre><code>import gin.tf </code></pre> <p>introduce the error:ModuleNotFoundError: No module named 'gin.tf'</p> <p>but the code:</p> <pre><code>import gin </code></p...
<p><a href="https://pypi.org/project/gin-config/" rel="nofollow noreferrer"><code>gin-config</code></a> is now at version 0.5.0. At the command line, enter</p> <pre class="lang-none prettyprint-override"><code>pip install -U gin-config </code></pre> <p>to update it to the most recent version, and you should be all set....
79
T5 model
A prepand *Paraphrase* is showig all the time after runnig the code instead of actual paraphrased Sentence
https://stackoverflow.com/questions/78673465/a-prepand-paraphrase-is-showig-all-the-time-after-runnig-the-code-instead-of-a
<p>I am creating an URDU TEXT PARAPHRASING tool for my semester.</p> <p>I have used T5 Model and fine tuned it.</p> <p>Now when im running this code:</p> <pre><code>**import torch from transformers import T5ForConditionalGeneration, T5Tokenizer # Define your model and tokenizer model_name = &quot;t5-small&quot; model ...
80
T5 model
Are there any potential issues training a T5-small from scratch on a task with very limited vocabulary?
https://stackoverflow.com/questions/78949531/are-there-any-potential-issues-training-a-t5-small-from-scratch-on-a-task-with-v
<p>Suppose you would like to train a sequence-to-sequence model like T5-small <strong>from scratch</strong> on a task where the vocabulary is quite limited compared to the tokenizer of T5 which was trained on much larger vocabulary.</p> <p>For instance, the data have the following format:</p> <pre><code>Can you please ...
81
T5 model
ImportError: attempted relative import with no known parent package in ONNX Library
https://stackoverflow.com/questions/66238009/importerror-attempted-relative-import-with-no-known-parent-package-in-onnx-libr
<p>I am converting the T5 model from pytorch to ONNX using <a href="https://github.com/onnx/models/blob/master/text/machine_comprehension/t5/dependencies/T5-export.py" rel="nofollow noreferrer">this</a> script, but I am running into an Import module error. I don't think this a structural problem as this script has been...
82
T5 model
Your fast tokenizer does not have the necessary information to save the vocabulary for a slow tokenizer
https://stackoverflow.com/questions/74529986/your-fast-tokenizer-does-not-have-the-necessary-information-to-save-the-vocabula
<p>I'm trying to fine tune a t5 model for paraphrasing Farsi sentences. I'm using <a href="https://huggingface.co/erfan226/persian-t5-paraphraser" rel="nofollow noreferrer">this</a> model as my base. My dataset is a paired sentence dataset which each row is a pair of paraphrased sentences. I want to fine tune the model...
83
T5 model
Using Google&#39;s T5 for translation from German to English
https://stackoverflow.com/questions/66797042/using-googles-t5-for-translation-from-german-to-english
<p>I am trying to use Google's T5 for language translation. However, it is not working for German to English.</p> <p>English to German works fine:</p> <pre><code>self.tokenizer = AutoTokenizer.from_pretrained(&quot;t5-small&quot;) self.model = AutoModelForSeq2SeqLM.from_pretrained(&quot;t5-small&quot;) inputs = self.to...
<p>Probably very late to the party, but I just printed out model.config as @acivic2nv suggested. It seems like the Google T5 model only supports translations from English to other languages, specifically: French, German, and Romanian.</p> <p>In case you are still looking for a model that is able to translate from Germa...
84
T5 model
Undefined symbol error when trying to load Huggingface&#39;s T5
https://stackoverflow.com/questions/75597709/undefined-symbol-error-when-trying-to-load-huggingfaces-t5
<h2>Issue</h2> <p>I tried to load T5 models from the Huggingface <code>transformers</code> library in python as follows</p> <pre><code>import pytorch import transformers from transformers import AutoModelForSeq2SeqLM plm = AutoModelForSeq2SeqLM.from_pretrained('t5-small') </code></pre> <p>The <code>AutoModel</code> li...
<p>I had a similar problem and I found that <code>pip uninstall apex</code> to remove apex package solved my problem.</p> <p>More precisely, I had the excact same problem as with <code>fairseq</code> but the solution proposed did not work. When I compared to colab where the code was running, <code>apex</code> was not ...
85
T5 model
Fine tuning T5 not converging
https://stackoverflow.com/questions/76932312/fine-tuning-t5-not-converging
<p>I am new in this world of transformers and NLP, and I am having a problem when fine tuning T5 for my specific use case.</p> <p>What I want to achieve, is that the model receives an input text, and outputs a JSON (as a string) of the relevant information in the text.</p> <p>There are 3 formats that the model can resp...
<p>It's been almost a year - did you solve this?</p> <p>I see two possible issues with your approach.</p> <p>(1) Trying to model randomness (?) You said:</p> <blockquote> <p>I've built a Python script to generate the inputs and labels as random as possible.</p> </blockquote> <p>If I understand correct - you are creatin...
86
T5 model
Semantic searching using Google flan-t5
https://stackoverflow.com/questions/75673222/semantic-searching-using-google-flan-t5
<p>I'm trying to use google flan t5-large to create embeddings for a simple semantic search engine. However, the generated embeddings cosine similarity with my query is very off. Is there something I'm doing wrong?</p> <pre class="lang-py prettyprint-override"><code>import torch from transformers import AutoTokenizer, ...
<p>The problem you face here is that you assume that FLAN's sentence embeddings are suited for similarity metrics, but that isn't the case. Jacob Devlin <a href="https://github.com/google-research/bert/issues/164#issuecomment-441324222" rel="noreferrer">wrote</a> once regarding BERT:</p> <blockquote> <p>I'm not sure wh...
87
T5 model
How to use Huggingface pretrained models to get the output of the dataset that was used to train the model?
https://stackoverflow.com/questions/69530032/how-to-use-huggingface-pretrained-models-to-get-the-output-of-the-dataset-that-w
<p>I am working on getting the abstractive summaries of the XSUM and the CNN DailyMail datasets using Huggingface's pre-trained BART, Pegasus, and T5 models.</p> <p>I am confused because there already exist checkpoints of models pre-trained on the same dataset.</p> <p>So even if I do:</p> <pre class="lang-py prettyprin...
88
T5 model
PEFT LoRA Trainer No executable batch size found
https://stackoverflow.com/questions/77404935/peft-lora-trainer-no-executable-batch-size-found
<p>I'm trying to fine tune the model weights from a FLAN-T5 model downloaded from hugging face. I'm trying to do this with PEFT and specifically LoRA. I'm using the code below. I'm getting an error &quot;No executable batch size found, reached zero&quot;. It seems to be related to the &quot;auto_find_batch_size&quo...
<p>It could be that <code>auto_find_batch_size</code> is not perfect in its process. It might have a value that would be too big to fit into the currently-available VRAM space, and so the training loop decides that it can't continue and errors out. I'm seeing this myself and that's the conclusion I've come to.</p> <p>I...
89
T5 model
T5Tokenizer requires the SentencePiece library but it was not found in your environment
https://stackoverflow.com/questions/65445651/t5tokenizer-requires-the-sentencepiece-library-but-it-was-not-found-in-your-envi
<p>I am trying to explore <a href="https://huggingface.co/transformers/model_doc/t5.html#" rel="noreferrer">T5</a></p> <p>this is the code</p> <pre><code>!pip install transformers from transformers import T5Tokenizer, T5ForConditionalGeneration qa_input = &quot;&quot;&quot;question: What is the capital of Syria? contex...
<p>I used these two command and this working fine for me!</p> <pre><code>!pip install datasets transformers[sentencepiece] !pip install sentencepiece </code></pre>
90
T5 model
MT5 machine learning model for paraphrasing
https://stackoverflow.com/questions/74149057/mt5-machine-learning-model-for-paraphrasing
<p>I'm trying to create a machine learning model to paraphrase given Persian text. I was introduced to mt5 as a multilingual text-to-text model. However, I can't figure out how to implement this. I have gathered the data. Here's a sample of the data: <a href="https://i.sstatic.net/qz6MC.jpg" rel="nofollow noreferrer">D...
<p>IMHO mT5 can't be used for paraphrase generation out-of-the-box, just like the T5 can. You can find fine-tuned versions of the T5 model intended for paraphrase generation on the HuggingFace Hub, such as <a href="https://huggingface.co/secometo/mt5-base-turkish-question-paraphrase-generator" rel="nofollow noreferrer"...
91
T5 model
Training step not executing in pytorch lightning
https://stackoverflow.com/questions/66756245/training-step-not-executing-in-pytorch-lightning
<p>I am working to finetune a t5 model to summarize Amazon reviews. I am following this tutorial here: <a href="https://towardsdatascience.com/fine-tuning-a-t5-transformer-for-any-summarization-task-82334c64c81" rel="nofollow noreferrer">https://towardsdatascience.com/fine-tuning-a-t5-transformer-for-any-summarization-...
<p>It seems that this code is quite outdated. What makes this conflict is the <code>optimizer_step()</code> method. I just commented out this whole segment below and it worked for me. If you want to do any custom logic in this function, better to consult the latest code on <a href="https://github.com/PyTorchLightning/p...
92
T5 model
How does the finetune on transformer (t5) work?
https://stackoverflow.com/questions/71781813/how-does-the-finetune-on-transformer-t5-work
<p>I am using pytorch lightning to finetune t5 transformer on a specific task. However, I was not able to understand how the finetuning works. I always see this code :</p> <p><code>tokenizer = AutoTokenizer.from_pretrained(hparams.model_name_or_path) model = AutoModelForSeq2SeqLM.fro...
<p>If you are using PyTorch Lightning, then it won't freeze the head until you specify it do so. Lightning has a callback which you can use to freeze your backbone and training only the head module. See <a href="https://pytorch-lightning.readthedocs.io/en/latest/api/pytorch_lightning.callbacks.BackboneFinetuning.html?h...
93
T5 model
What decoder_input_ids should be for sequence-to-sequence Transformer model?
https://stackoverflow.com/questions/63307009/what-decoder-input-ids-should-be-for-sequence-to-sequence-transformer-model
<p>I use the HuggingFace's Transformers library for building a <strong>sequence-to-sequence model</strong> based on BART and T5. I carefully read the documentation and the research paper and I can't find what the input to the decoder (decoder_input_ids) should be for sequence-to-sequence tasks.</p> <p>Should decoder in...
<p>The decoder_input_ids (optional) corresponds to labels, and labels are the preferred way to provide decoder_input_ids. <a href="https://huggingface.co/transformers/glossary.html#decoder-input-ids" rel="nofollow noreferrer">https://huggingface.co/transformers/glossary.html#decoder-input-ids</a></p> <p>This is because...
94
T5 model
Avoid printing &#39;Generate config GenerationConfig { ... }&#39;
https://stackoverflow.com/questions/76902234/avoid-printing-generate-config-generationconfig
<p>I am facing an issue while training a t5 model. After each evaluation step, the following message is printed, which makes it impossible to maintain an overview. Do you have any ideas, on how I can avoid such behavior?</p> <blockquote> <p>***** Running Evaluation ***** Num examples = 819 Batch size = 32 Generate ...
95
T5 model
CUDA out of memory error during PEFT LoRA fine tuning
https://stackoverflow.com/questions/77406208/cuda-out-of-memory-error-during-peft-lora-fine-tuning
<p>I'm trying to fine-tune the model weights from a FLAN-T5 model downloaded from hugging face. I'm trying to do this with PEFT and specifically LoRA. I'm using the Python 3 code below. I'm running this on ubuntu server 18.04LTS with an invidia gpu that has 8GB of ram. I'm getting an error &quot;CUDA out of memory&quot...
<p>Have you tried with re-enabling gradient_checkpointing or enabling it at all? According to <a href="https://huggingface.co/docs/transformers/v4.18.0/en/performance" rel="nofollow noreferrer">https://huggingface.co/docs/transformers/v4.18.0/en/performance</a> even if everything else is set up fine, it might happen th...
96
T5 model
How to use Huggingface Transformers with PrimeQA model?
https://stackoverflow.com/questions/73357305/how-to-use-huggingface-transformers-with-primeqa-model
<p>Here is the model <a href="https://huggingface.co/PrimeQA/t5-base-table-question-generator" rel="nofollow noreferrer">https://huggingface.co/PrimeQA/t5-base-table-question-generator</a></p> <p>Hugging face says that I should use the following code to use the model in transformers:</p> <pre><code>from transformers im...
<p>You can load <code>PrimeQA/t5-base-table-question-generator</code> model using the Huggingface transformers library directly. However you cannot call the function <code>generate_questions</code>. This is because the function <code>generate_questions</code> is defined in the class <a href="https://github.com/primeqa/...
97
T5 model
pytorch model saved from TPU run on CPU
https://stackoverflow.com/questions/63419835/pytorch-model-saved-from-tpu-run-on-cpu
<p>I found interesting model - question generator, but can't run it. I got an error:</p> <pre><code>Traceback (most recent call last): File &quot;qg.py&quot;, line 5, in &lt;module&gt; model = AutoModelWithLMHead.from_pretrained(&quot;/home/user/ml-experiments/gamesgen/t5-base-finetuned-question-generation-ap/&qu...
<p>As @cronoik suggested, I have installed <code>transformers</code> library form github. I clonned latest version, and executed <code>python3 setup.py install</code> in it's directory. This bug was fixed, but fix still not released in python's packets repository.</p>
98
T5 model
In the original T5 paper, what does &#39;step&#39; mean?
https://stackoverflow.com/questions/75432369/in-the-original-t5-paper-what-does-step-mean
<p>I have been reading the original T5 paper 'Exploring the limits of transfer learning with a unified text-to-text transformer.' On page 11, it says &quot;We pre-train each model for 2^19=524,288 <strong>steps</strong> on C4 before fine-tuning.&quot;</p> <p>I am not sure what the '<strong>steps</strong>' mean. Is it t...
<p>A step is a single training iteration. In a step, the model is given a single batch of training instances. So if the batch size is <code>128</code>, then the model is exposed to 128 instances in a single step.</p> <p>Epochs aren't the same as steps. An epoch is a single pass over an entire training set. So if the tr...
99
BERT model
Retrain a BERT Model
https://stackoverflow.com/questions/70080219/retrain-a-bert-model
<p>I have trained a BERT model using pytorch for about a million text data for a classification task. After testing this model with new data I get False Positives and False Negatives. Now I want retrain the existing model only with FN and FP. I do not want to append the FN and FP to the exisiting dataset and then train...
<p>Without knowing the code for your train loop, the idea should look something like this after training:</p> <pre><code>results = model(data) wrong_datapoints = [] for i, result in enumerate(results) if result != labels[i]: wrong_datapoints.append((data[i],labels[i])) (data_new, labels_new) = list(zip(*...
100
BERT model
Unable to fit BERT model
https://stackoverflow.com/questions/66844078/unable-to-fit-bert-model
<p>I am trying to train a BERT model based on an online tutorial (Coursera). The objective is to use the Quora insincere questions data to train a BERT model. The entire code is shown below:</p> <pre><code># Function to fine-tune BERT for Text Classification # bert_layer = hub.KerasLayer('https://tfhub.dev/tensorflow/b...
101
BERT model
Bert model splits words by its own
https://stackoverflow.com/questions/76238212/bert-model-splits-words-by-its-own
<p>I am tokenizing the input words using bert model. The code is :</p> <pre><code>tokenizer = BertTokenizer.from_pretrained('bert-base-multilingual-cased',do_lower_case = False) model = BertModel.from_pretrained(&quot;bert-base-multilingual-cased&quot;, add_pooling_layer=False, output_hidden_states=True, output_attenti...
<p>You are not doing anything wrong. Bert uses a so-called <a href="https://huggingface.co/docs/transformers/tokenizer_summary#wordpiece" rel="nofollow noreferrer">wordpiece</a> subword tokenizer as a compromise for meaningful embeddings and acceptable memory consumption between a character-level (small vocabulary) and...
102
BERT model
Add dense layer on top of Huggingface BERT model
https://stackoverflow.com/questions/64156202/add-dense-layer-on-top-of-huggingface-bert-model
<p>I want to add a dense layer on top of the bare BERT Model transformer outputting raw hidden-states, and then fine tune the resulting model. Specifically, I am using <a href="https://huggingface.co/dbmdz/bert-base-italian-xxl-cased" rel="noreferrer">this</a> base model. This is what the model should do:</p> <ol> <li>...
<p>There are two ways to do it: Since you are looking to fine-tune the model for a downstream task similar to classification, you can directly use:</p> <p><code>BertForSequenceClassification</code> class. Performs fine-tuning of logistic regression layer on the output dimension of 768.</p> <p>Alternatively, you can def...
103
BERT model
Load bert model in java
https://stackoverflow.com/questions/61000862/load-bert-model-in-java
<p>I have bert model for named entity recognition.(config.json, model.bin, vocab.txt). I can load model and get named entities from text with model in python</p> <pre><code>input_text = "I live in London" model_dir = "/content/gdrive/My Drive/models/v1" print (get_predictions(input_text, model_dir) ) </code></pre> ...
104
BERT model
Does Bert model need text?
https://stackoverflow.com/questions/70649831/does-bert-model-need-text
<p>Does Bert models need pre-processed text (Like removing special characters, stopwords, etc.) or I can directly pass my text as it is to Bert models. (HuggigFace libraries).</p> <p><em>note</em>: Follow up question to: <a href="https://stackoverflow.com/questions/70067901/string-cleaning-preprocessing-for-bert">Strin...
<p>Cleaning the input text for transformer models is not required. Removing stop words (which are considered as noise in conventional text representation like bag-of-words or tf-idf) can and <strong>probably will worsen</strong> the predictions of your BERT model.</p> <p>Since BERT is making use of the self-attention m...
105
BERT model
Updating a BERT model through Huggingface transformers
https://stackoverflow.com/questions/58620282/updating-a-bert-model-through-huggingface-transformers
<p>I am attempting to update the pre-trained BERT model using an in house corpus. I have looked at the Huggingface transformer docs and I am a little stuck as you will see below.My goal is to compute simple similarities between sentences using the cosine distance but I need to update the pre-trained model for my specif...
<p>BERT is pre-trained on 2 tasks: masked language modeling (MLM) and next sentence prediction (NSP). The most important of those two is MLM (it turns out that the next sentence prediction task is not really that helpful for the model's language understanding capabilities - RoBERTa for example is only pre-trained on ML...
106
BERT model
Loading pretrained BERT model issue
https://stackoverflow.com/questions/66442648/loading-pretrained-bert-model-issue
<p>I am using Huggingface to further train a BERT model. I saved the model using two methods: step (1) Saving the entire model using this code: <code>model.save_pretrained(save_location)</code>, and step (2) save the state_dict of the model using this code: <code>torch.save(model.state_dict(),'model.pth')</code> Howeve...
<p>I was going through the same thing. Turns out that this might be due to version indifference of both PyTorch and transformers. It has to be version-specific.</p> <p>I used the following without downloading the latest bert-base-uncased model :</p> <pre><code>pip install torch==1.5.1 pip install transformers==3.0.2 M...
107
BERT model
Saving a &#39;fine-tuned&#39; bert model
https://stackoverflow.com/questions/59340061/saving-a-fine-tuned-bert-model
<p>I am trying to save a fine tuned bert model. I have ran the code correctly - it works fine, and in the ipython console I am able to call getPrediction and have it result the result. </p> <p>I have my weight files saved (highest being model.ckpt-333.data-00000-of-00001</p> <p>I have no idea how I would go about sav...
<p>As the question clearly says to save the model, here is how it works:</p> <pre><code>import torch torch.save(model, 'path/to/model') saved_model = torch.load('path/to/model') </code></pre>
108
BERT model
Saving bert model at every epoch for further training
https://stackoverflow.com/questions/70922216/saving-bert-model-at-every-epoch-for-further-training
<p>I am using <code>bert_model.save_pretrained</code> for saving the model at end as this is the command that helps in saving the model with all configurations and weights but this cannot be used in model.fit command as in callbacks saving model at each epoch does not save with save_pretrained. Can anybody help me in s...
109
BERT model
Training a BERT model and using the BERT embeddings
https://stackoverflow.com/questions/63476702/training-a-bert-model-and-using-the-bert-embeddings
<p>I've been reading up on BERT and using BERT embeddings for a classification task. I've read many articles but my understanding of it still is not 100% (I have self-taught myself NLP, so my access to resources can be a bit restricted). First I'll describe my task.</p> <p>I was planning on using BERT embeddings for cl...
<p>I'm just like you, a self knowledge teacher of NLP. Since you have not started yet (you'll have such a quiet journey, don't you?), I would recommend you to check this proyect in <code>tensorflow</code> library since it's from Google and you'll have better access to all its power (just my opinion):</p> <p>First, you'...
110
BERT model
Compare cosine similarity of word with BERT model
https://stackoverflow.com/questions/69784408/compare-cosine-similarity-of-word-with-bert-model
<p>Hi I am looking to generate similar words for a word using BERT model, the same approach we use in gensim to generate most_similar word, I found the approach as:</p> <pre><code>from transformers import BertTokenizer, BertModel import torch tokenizer = BertTokenizer.from_pretrained('bert-base-uncased') model = Ber...
<p>Seems like you need to store embeddings for all word from your vocabulary. After that, you can use some tools to find the closest embedding to the target embedding. For example, you can use <a href="https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.NearestNeighbors.html#sklearn.neighbors.NearestNei...
111
BERT model
Evaluate BERT Model param.requires_grad
https://stackoverflow.com/questions/72687276/evaluate-bert-model-param-requires-grad
<p>I have a doubt regarding the evaluation on the test set of my bert model. During the eval part param.requires_grad is suppose to be True or False? indipendently if I did a full fine tuning during training or not. My model is in model.eval() mode but I want to be sure to not force nothing wrong in the Model() class w...
<p>If you freeze your model then the parameter of the corresponding modules must not be updated, <em>i.e.</em> they should not require gradient computation: <code>requires_grad=False</code>.</p> <p>Note <a href="https://pytorch.org/docs/stable/generated/torch.nn.Module.html" rel="nofollow noreferrer"><code>nn.Module</c...
112
BERT model
BERT finetuning : Is it right to train BERT Classification model at once?
https://stackoverflow.com/questions/68524992/bert-finetuning-is-it-right-to-train-bert-classification-model-at-once
<p>I have a question about training BERT classification(or pretrained model).</p> <p>BERT classifier model usually constructed 2 models. BERT model and classifier.</p> <p>Many BERT fine tuning example code is training BERT model and classifier layer at once. But I think, classifier is training first and BERT weight sho...
<p>There are two ways to train a BERT-based classification model:</p> <ol> <li><p><strong>Finetuning</strong>: Which is the practice of training your classifier along with your text encoder (BERT in this case, but it can be any other text encoder, e.g., RoBERTa, ALBERT...). In this setting, the encoder and the classifi...
113
BERT model
Getting PermissionError while saving BERT model checkpoint
https://stackoverflow.com/questions/77875404/getting-permissionerror-while-saving-bert-model-checkpoint
<p>I am finetuning a BERT model for classification task, Following code is used for the training the model.</p> <pre><code>from transformers import Trainer, TrainingArguments, AutoConfig from transformers import Trainer batch_size = 8 logging_steps = len(emotions_encoded['train']) // batch_size print(len(emotions_enco...
<p>There is a <a href="https://discuss.huggingface.co/t/permission-issues-when-saving-model-checkpoint/70109/2" rel="nofollow noreferrer">discussion on HF</a> that solves this issue.</p> <blockquote> <p>I simply remove those lines of line. In this example, I basically removed lines 2417-2420. It appears to still work f...
114
BERT model
Convert a BERT Model to TFLite
https://stackoverflow.com/questions/60967842/convert-a-bert-model-to-tflite
<p>I have this code for semantic search engine built using the pre-trained bert model. I want to convert this model into tflite for deploying it to google mlkit. I want to know how to convert it. I want to know if its even possible to convert this into tflite. It might be because its mentioned on the official tensorflo...
<p>First of all, you need to have your model in TensorFlow, the package you are using is written in PyTorch. Huggingface's <a href="https://github.com/huggingface/transformers" rel="nofollow noreferrer">Transformers</a> has TensorFlow models that you can start with. In addition, they also have <a href="https://github.c...
115
BERT model
Number of parameters in BERT model
https://stackoverflow.com/questions/78997967/number-of-parameters-in-bert-model
<p>Suppose you are pretraining a BERT model with 8 layers, 768-dim hidden states, 8 attention heads, and a sub-word vocabulary of size 40k. Also, your feed-forward hidden layer is of dimension 3072. What will be the number of parameters of the model? You can ignore the bias terms, and other parameters used correspondin...
116
BERT model
BERT tokenizer &amp; model download
https://stackoverflow.com/questions/59701981/bert-tokenizer-model-download
<p>I`m beginner.. I'm working with Bert. However, due to the security of the company network, the following code does not receive the bert model directly.</p> <pre><code>tokenizer = BertTokenizer.from_pretrained('bert-base-multilingual-cased', do_lower_case=False) model = BertForSequenceClassification.from_pretrained(...
<p>As described <a href="https://github.com/huggingface/transformers/issues/856" rel="noreferrer">here</a>, what you need to do are download <code>pre_train</code> and <code>configs</code>, then putting them in the same folder. Every model has a pair of links, you might want to take a look at lib code. </p> <p>For ins...
117
BERT model
Tensorflow serving keras bert model issue
https://stackoverflow.com/questions/79154761/tensorflow-serving-keras-bert-model-issue
<p>I am trying to use tensorflow serving to serve a keras bert model, but I have problem to predict with rest api, below are informations. Can you please help me to resolve this problem.</p> <h1>predict output (ERROR)</h1> <p>{ &quot;error&quot;: &quot;Op type not registered 'TFText&gt;RoundRobinTrim' in binary running...
118
BERT model
Bert model for word similarity
https://stackoverflow.com/questions/75531115/bert-model-for-word-similarity
<p>I'm quite new to NLP, and I want to calculate the similarity between a given word and each word in a given list. I have the following code</p> <pre><code># Load the BERT model model_name = 'bert-base-uncased' tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModel.from_pretrained(model_name) # Encod...
<p>First of all, the similarity is a tricky word because there are different types of similarities. Especially semantic and sentimental similarities are very different concepts. For example, while good and bad are sentimental opposite words, they are semantically similar words. The basic BERT model is trained to captur...
119
BERT model
Error loading quantized BERT model from local repository
https://stackoverflow.com/questions/68226106/error-loading-quantized-bert-model-from-local-repository
<p>After quantizing the BERT model, it works without any issue. But if I save the quantized model and load, it does not work. It shows an error message: 'LinearPackedParams' object has no attribute '_modules&quot;. I have used the same device to save and load the quantized model.</p> <pre><code>model = SentenceTransfor...
120
BERT model
Need to Fine Tune a BERT Model to Predict Missing Words
https://stackoverflow.com/questions/60486655/need-to-fine-tune-a-bert-model-to-predict-missing-words
<p>I'm aware that BERT has a capability in predicting a missing word within a sentence, which can be syntactically correct and semantically coherent. Below is a sample code:</p> <pre><code>import torch from pytorch_pretrained_bert import BertTokenizer, BertForMaskedLM tokenizer = BertTokenizer.from_pretrained('bert-b...
<p>BERT is a masked Language Model, meaning it is trained on exactly this task. That is why it can do it. So in that sense, no fine tuning is needed.</p> <p>However, if the text you will see at runtime is different than the text BERT was trained on, your performance may be much better if you fine tune on the type of t...
121
BERT model
How to feed the output of a finetuned bert model as inpunt to another finetuned bert model?
https://stackoverflow.com/questions/60297908/how-to-feed-the-output-of-a-finetuned-bert-model-as-inpunt-to-another-finetuned
<p>I finetuned two separate bert model (bert-base-uncased) on sentiment analysis and pos tagging tasks. Now, I want to feed the output of the pos tagger (batch, seqlength, hiddensize) as input to the sentiment model.The original bert-base-uncased model is in 'bertModel/' folder which contains 'model.bin' and 'config.js...
<p>To formulate this as an answer, too, and keep it properly visible for future visitors, the <code>forward()</code> call of transformers <a href="https://github.com/huggingface/transformers/blob/v2.1.1/transformers/modeling_bert.py#L201" rel="nofollow noreferrer">does not support these arguments in version 2.1.1</a>, ...
122
BERT model
Fine-tune a BERT model for context specific embeddigns
https://stackoverflow.com/questions/67136740/fine-tune-a-bert-model-for-context-specific-embeddigns
<p>I'm trying to find information on how to train a BERT model, possibly from the <a href="https://huggingface.co/transformers/index.html" rel="noreferrer">Huggingface Transformers</a> library, so that the embedding it outputs are more closely related to the context o the text I'm using.</p> <p>However, all the example...
<p>Here is an example from the Transformers library on <a href="https://colab.research.google.com/github/huggingface/notebooks/blob/master/examples/language_modeling.ipynb#scrollTo=a3KD3WXU3l-O" rel="nofollow noreferrer">Fine tuning a language model for masked token prediction</a>.</p> <p>The model that is used is one ...
123
BERT model
Bert Model not loading with pickle
https://stackoverflow.com/questions/74689390/bert-model-not-loading-with-pickle
<p>I trained a Bert Model for NER. It worked fine (obviously it took time to learn). I saved the model with <code>pickle</code> as</p> <pre><code>with open('model_pkl', 'wb') as file: pickle.dump(model, file) </code></pre> <p>When I am trying to load this saved model I am getting following error. <code>AttributeEr...
<p>Try using <a href="https://pytorch.org/tutorials/beginner/basics/saveloadrun_tutorial.html#saving-and-loading-models-with-shapes" rel="nofollow noreferrer">torch.save and torch.load</a>.</p>
124
BERT model
Text classification using BERT model
https://stackoverflow.com/questions/67356712/text-classification-using-bert-model
<p>I have built and trained the BERT model, using <a href="https://github.com/curiousily/Deep-Learning-For-Hackers/blob/master/18.intent-recognition-with-BERT.ipynb" rel="nofollow noreferrer">this code</a>.</p> <p>Now I have this data:</p> <p><a href="https://i.sstatic.net/z6ALu.png" rel="nofollow noreferrer"><img src=...
125
BERT model
QnA model using Bert
https://stackoverflow.com/questions/76027510/qna-model-using-bert
<p>I'm trying to build a bert model containing document as input. As bert's limitation is 512 tokens, it's unable to give accurate answer. Now, I'm trying to find NLP model/way/algorithm which should help bert model to find the correct answer.</p> <p>I tried with document as input and was expecting accurate answer as i...
<p>In the <strong>Extractive Question Answering task</strong>, in order to extract answer from the context (in this case, your input document), it is usually solved by <strong>BERT-like</strong> model.</p> <p>According to your case, there has a limitation that you have a long document to extract an answer out. however,...
126
BERT model
BERT model classification with many classes
https://stackoverflow.com/questions/64278341/bert-model-classification-with-many-classes
<p>I want to train a BERT model to perform a multiclass text classification. I use transformers and followed this tutorial (<a href="https://towardsdatascience.com/multi-class-text-classification-with-deep-learning-using-bert-b59ca2f5c613" rel="nofollow noreferrer">https://towardsdatascience.com/multi-class-text-classi...
127
BERT model
Loading trained BERT models locally in Pycharm
https://stackoverflow.com/questions/76830364/loading-trained-bert-models-locally-in-pycharm
<p>I am working on a project that have to train a Bert model myself, and later adapts that into Pycharm for GUI and more logic. It's a binary classification model. I wrote the script, and successfully trained a Bert model in Google Colab. I did it by</p> <pre><code>trainer.save_model(models) </code></pre> <p>It generat...
128
BERT model
Data classification doesn&#39;t work with BERT model
https://stackoverflow.com/questions/78936387/data-classification-doesnt-work-with-bert-model
<p>I need to train model with input CSV, that has error message and error classification. Then when tested with just error message, it should automatically classify.</p> <p>I've used BERT model and this is the code:</p> <pre><code>import pandas as pd import numpy as np import tensorflow as tf from transformers import B...
129
BERT model
google colab memory problem using bert model
https://stackoverflow.com/questions/78424613/google-colab-memory-problem-using-bert-model
<p>Question : i try to use a bert model for an essay to code my sequence with a NPL models , but it takes a lot of time and befor terminate his 1 epoch he get out of connection problem , and when i increase the batch size to 16 or 32 i get memory problem , this is my code so if i have a problem please tell me to solve ...
<p>I my opinion, you can try:</p> <ul> <li>Using &quot;adafactor&quot; optimizer [https://huggingface.co/docs/transformers/main_classes/optimizer_schedules][1]</li> <li>Gradient Accumulation [https://huggingface.co/docs/accelerate/usage_guides/gradient_accumulation][2]</li> <li>Training model with multi GPU to share pa...
130
BERT model
Print Bert model summary using Pytorch
https://stackoverflow.com/questions/71248696/print-bert-model-summary-using-pytorch
<p>Hi I would like to print the model summary of my BERT model for text classification. I am using command print(summary(model, inputsize=(channels, height, width)). I would like to know what would be the dimensions of input_size in case of text classification? I have use print(model) as well but the output is confusin...
<p>I used torch-summary module-</p> <pre><code>pip install torch-summary summary(model,input_size=(768,),depth=1,batch_dim=1, dtypes=[‘torch.IntTensor’]) </code></pre>
131
BERT model
Why BERT model have to keep 10% MASK token unchanged?
https://stackoverflow.com/questions/64013808/why-bert-model-have-to-keep-10-mask-token-unchanged
<p>I am reading BERT model paper. In Masked Language Model task during pre-training BERT model, the paper said the model will choose 15% token ramdomly. In the chose token (Ti), 80% it will be replaced with [MASK] token, 10% Ti is unchanged and 10% Ti replaced with another word. I think the model just need to replace w...
<p>This is done because they want to pre-train a bidirectional model. Most of the time the network will see a sentence with a [MASK] token, and its trained to predict the word that is supposed to be there. But in fine-tuning, which is done after pre-training (fine-tuning is the training done by everyone who wants to us...
132
BERT model
How to load a fine-tuned BERT model
https://stackoverflow.com/questions/62448553/how-to-load-a-fine-tuned-bert-model
<p>I have fine tuned a BERT model on my data and saved the model using <code>model.save()</code></p> <p>now am trying to load using the below</p> <pre><code>from keras_radam import RAdam from keras.models import load_model from keras_bert import get_custom_objects custom_object = get_custom_objects() custom_object['...
133