AliOsm / simplerepresentations

Easy-to-use text representations extraction library based on the Transformers library.
Apache License 2.0
32 stars 4 forks source link

Example code not working #4

Closed SeanPedersen closed 1 year ago

SeanPedersen commented 3 years ago

Just pip installed and tried the README example code, does not work, throws following exception:

----> 1 all_sentences_representations, all_tokens_representations = representation_model(text_a=load_data()) 2 3 print(all_sentences_representations.shape) # (2, 768) => (number of sentences, hidden size) 4 print(all_tokens_representations.shape) # (2, 10, 3072) => (number of sentences, number of tokens, hidden size

1 frames

/usr/local/lib/python3.6/dist-packages/simplerepresentations/representationmodel.py in (.0) 113 , sentences_representations, tokens_representations = self.model(**inputs) 114 --> 115 sentences_representations = np.array([sentences_representation.cpu().numpy() for sentences_representation in sentences_representations]) 116 all_sentences_representations.extend(sentences_representations) 117 elif self.model_type in self.MODELS_WO_SENREP:

AttributeError: 'str' object has no attribute 'cpu'

gaobonan commented 3 years ago

Same problem. I change the bert model as model_type = 'bert' model_name = 'bert-base-uncased' Then it works.

pedro-alonsod commented 3 years ago

Same here.