title: Pytorch error "RuntimeError: index out of range: Tried to access index 512 out of table with 511 rows"
body: <p>I have sentences that I vectorize using sentence_vector() method of BiobertEmbedding python module (<a href="https://pypi.org/project/biobert-embedding/" rel="nofollow noreferrer">https://pypi.org/project/biobert-embedding/</a>). For some group of sentences I have no problem but for some others I have the following error message :</p>
  <blockquote>
  <p>File
  &quot;/home/nobunaga/.local/lib/python3.6/site-packages/biobert_embedding/embedding.py&quot;,
  line 133, in sentence_vector
  encoded_layers = self.eval_fwdprop_biobert(tokenized_text)   File &quot;/home/nobunaga/.local/lib/python3.6/site-packages/biobert_embedding/embedding.py&quot;,
  line 82, in eval_fwdprop_biobert
  encoded_layers, _ = self.model(tokens_tensor, segments_tensors)   File
  &quot;/home/nobunaga/.local/lib/python3.6/site-packages/torch/nn/modules/module.py&quot;,
  line 547, in __call__
  result = self.forward(*input, **kwargs)   File &quot;/home/nobunaga/.local/lib/python3.6/site-packages/pytorch_pretrained_bert/modeling.py&quot;,
  line 730, in forward
  embedding_output = self.embeddings(input_ids, token_type_ids)   File
  &quot;/home/nobunaga/.local/lib/python3.6/site-packages/torch/nn/modules/module.py&quot;,
  line 547, in __call__
  result = self.forward(*input, **kwargs)   File &quot;/home/nobunaga/.local/lib/python3.6/site-packages/pytorch_pretrained_bert/modeling.py&quot;,
  line 268, in forward
  position_embeddings = self.position_embeddings(position_ids)   File
  &quot;/home/nobunaga/.local/lib/python3.6/site-packages/torch/nn/modules/module.py&quot;,
  line 547, in __call__
  result = self.forward(*input, **kwargs)   File &quot;/home/nobunaga/.local/lib/python3.6/site-packages/torch/nn/modules/sparse.py&quot;,
  line 114, in forward
  self.norm_type, self.scale_grad_by_freq, self.sparse)   File &quot;/home/nobunaga/.local/lib/python3.6/site-packages/torch/nn/functional.py&quot;,
  line 1467, in embedding
  return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse) RuntimeError: index out of range: Tried to
  access index 512 out of table with 511 rows. at
  /pytorch/aten/src/TH/generic/THTensorEvenMoreMath.cpp:237</p>
  </blockquote>
  <p>I discovered that for some group of sentences, the problem was related to tags like <code>&lt;tb&gt;</code> for instance. But for others, even when tags are removed, the error message is still there.<br />
  (Unfortunately I can't share the code for confidentiality reasons)</p>
  <p>Do you have any ideas of what could be the problem?</p>
  <p>Thank you by advance</p>
  <p>EDIT : you are right cronoik, it will be better with an example.</p>
  <p>Example :</p>
  <pre><code>sentences = [&quot;This is the first sentence.&quot;, &quot;This is the second sentence.&quot;, &quot;This is the third sentence.&quot;
  
  biobert = BiobertEmbedding(model_path='./biobert_v1.1_pubmed_pytorch_model')
  
  vectors = [biobert.sentence_vector(doc) for doc in sentences]
  </code></pre>
  <p>This last line of code is what caused the error message in my opinion.</p>