Closed khalidbhs closed 4 years ago
Thanks for reporting this bug @khalidbhs !
For model_format='transformers'
: Edge case where the model name contains "bert" and therefore the BERT tokenizer is loaded instead of the XLMR tokenizer. We'll fix this.
For model_format='sentence-transformers'
: Not clear yet what is happening here. Possibly some version issues. What transformers + sentence-transformers version do you use?
Cool, thanks!
I used transformers==3.1.0
and sentence-transformers==0.3.4
Here's the full stack trace for model_format='sentence-transformers'
btw:
ValueError Traceback (most recent call last)
<ipython-input-24-d3ac4f6b76bb> in <module>()
----> 1 retriever.embed('test')
7 frames
/usr/local/lib/python3.6/dist-packages/haystack/retriever/dense.py in embed(self, texts)
347 # text is single string, sentence-transformers needs a list of strings
348 # get back list of numpy embedding vectors
--> 349 emb = self.embedding_model.encode(texts) # type: ignore
350 emb = [r for r in emb]
351 return emb
/usr/local/lib/python3.6/dist-packages/sentence_transformers/SentenceTransformer.py in encode(self, sentences, batch_size, show_progress_bar, output_value, convert_to_numpy, convert_to_tensor, is_pretokenized, device, num_workers)
150
151 with torch.no_grad():
--> 152 out_features = self.forward(features)
153 embeddings = out_features[output_value]
154
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/container.py in forward(self, input)
115 def forward(self, input):
116 for module in self:
--> 117 input = module(input)
118 return input
119
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
720 result = self._slow_forward(*input, **kwargs)
721 else:
--> 722 result = self.forward(*input, **kwargs)
723 for hook in itertools.chain(
724 _global_forward_hooks.values(),
/usr/local/lib/python3.6/dist-packages/sentence_transformers/models/Transformer.py in forward(self, features)
33 def forward(self, features):
34 """Returns token_embeddings, cls_token"""
---> 35 output_states = self.auto_model(**features)
36 output_tokens = output_states[0]
37
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
720 result = self._slow_forward(*input, **kwargs)
721 else:
--> 722 result = self.forward(*input, **kwargs)
723 for hook in itertools.chain(
724 _global_forward_hooks.values(),
/usr/local/lib/python3.6/dist-packages/transformers/modeling_bert.py in forward(self, input_ids, attention_mask, token_type_ids, position_ids, head_mask, inputs_embeds, encoder_hidden_states, encoder_attention_mask, output_attentions, output_hidden_states, return_dict)
802 # We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length]
803 # ourselves in which case we just need to make it broadcastable to all heads.
--> 804 extended_attention_mask: torch.Tensor = self.get_extended_attention_mask(attention_mask, input_shape, device)
805
806 # If a 2D ou 3D attention mask is provided for the cross-attention
/usr/local/lib/python3.6/dist-packages/transformers/modeling_utils.py in get_extended_attention_mask(self, attention_mask, input_shape, device)
260 raise ValueError(
261 "Wrong shape for input_ids (shape {}) or attention_mask (shape {})".format(
--> 262 input_shape, attention_mask.shape
263 )
264 )
ValueError: Wrong shape for input_ids (shape torch.Size([4])) or attention_mask (shape torch.Size([4]))
Fixing this in https://github.com/deepset-ai/FARM/issues/571
Will be available in Haystack within the next days (after the FARM release) or you install the latest FARM version from master manually.
Great, I've tried it and it's working now, thanks!
Perfect, thanks for the feedback!
I'm trying to use
xlm-r-100langs-bert-base-nli-stsb-mean-tokens
as retriever withwhen I try to embed a text with
retriever.embed('test')
, it raises this error:I also tried to use the model from huggingface model hub:
but it raises this error:
Any advice how to use the
xlm-r-100langs-bert-base-nli-stsb-mean-tokens
model correctly?