Im running this code with en_core_web_sm 2.2.5
>>> import spacy
>>> nlp = spacy.load('en_core_web_sm', parser=False)
>>> print(nlp.vocal[u'fun'].similarity(nlp.vocal[u'humour']))
Traceback (most recent call last): File "", line 1, in
AttributeError: 'English' object has no attribute 'vocal'
First of all, I think you meant vocab instead of vocal.
Second of all, you are trying to access the word-vector and vocab has nothing to do with that.
Finally, you are using the en_core_web_sm model which doesn't support word-vectors according to spaCy official documentation here.
My suggestion is to use en_core_web_md instead. You can download it using the following command:
python -m spacy download en_core_web_md
And you can change your code to be:
>>> import spacy
>>> nlp = spacy.load('en_core_web_md', parser=False)
>>> nlp.(u'fun').similarity(nlp(u'humour'))
0.43595678034197044
Related
I am trying to use XLNET through transformers. however i keep getting the issue "AttributeError: 'NoneType' object has no attribute 'tokenize'". I am unsure of how to proceed. if anyone could point me in the right direction it would be appreciated.
tokenizer = XLNetTokenizer.from_pretrained('xlnet-base-cased', do_lower_case=True)
print(' Original: ', X_train[1])
# Print the tweet split into tokens.
print('Tokenized: ', tokenizer.tokenize(X_train[1]))
# Print the tweet mapped to token ids.
print('Token IDs: ', tokenizer.convert_tokens_to_ids(tokenizer.tokenize(X_train[1])))
Original: hey angel duh sexy really thanks haha
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-67-2b1b432b3e15> in <module>()
2
3 # Print the tweet split into tokens.
----> 4 print('Tokenized: ', tokenizer.tokenize(X_train[2]))
5
6 # Print the tweet mapped to token ids.
AttributeError: 'NoneType' object has no attribute 'tokenize'
I assume that:
from transformers import XLNetTokenizerFast
tokenizer = XLNetTokenizerFast.from_pretrained('xlnet-base-cased', do_lower_case=True)
works?
In this case, you are just missing the sentencepiece package:
pip install sentencepiece
In case SenencePience is installed and still have the error
Absolutely, #cronoik 's answer is the correct one. No doubt regarding it. But if you have installed the SenencePience package and still have the error, just restart the runtime environment and it will work.
As I'm trying to store a PNG image file into my riakBucket. As per https://riak-python-client.readthedocs.io/en/1.5-stable/tutorial.html documentation described here actually using riakBucketObject.new_binary().
But when I'm trying to do this over my system, this error is pop-up:
My python script is :
>>> import riak
>>> myClient = riak.RiakClient(pb_port=8087, protocol='pbc')
>>> photo_bucket = myClient.bucket('photo-bucket')
>>> file_data = open('/home/kamli/Pictures/Store3.png','rb').read()
>>> key = photo_bucket.new_binary('myphoto', data=file_data, content_type='image/png')
But error is :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'RiakBucket' object has no attribute 'new_binary'
System Configuration:
Python version - 2.7.6
Riak Version - 2.2.0
Riak 2.2 has changed since 1.5 and the current method to get a new RiakObject from a bucket is simply using RiakBucket.new() or RiakBucket.new_from_file(). The documentation can be found on their readthedocs website. Look for the version switcher near the bottom to look at documentation for each major release.
In addition to what Aaron3468 said, I would like to mention that the Riak Python Client's version does not match Riak's version. The client is versioned according to semver and the latest release is available here.
Please use the latest documentation.
I'm calling xgboost via its scikit-learn-style Python interface:
model = xgboost.XGBRegressor()
%time model.fit(trainX, trainY)
testY = model.predict(testX)
Some sklearn models tell you which importance they assign to features via the attribute feature_importances. This doesn't seem to exist for the XGBRegressor:
model.feature_importances_
AttributeError Traceback (most recent call last)
<ipython-input-36-fbaa36f9f167> in <module>()
----> 1 model.feature_importances_
AttributeError: 'XGBRegressor' object has no attribute 'feature_importances_'
The weird thing is: For a collaborator of mine the attribute feature_importances_ is there! What could be the issue?
These are the versions I have:
In [2]: xgboost.__version__
Out[2]: '0.6'
In [4]: sklearn.__version__
Out[4]: '0.18.1'
... and the xgboost C++ library from github, commit ef8d92fc52c674c44b824949388e72175f72e4d1.
How did you install xgboost? Did you build the package after cloning it from github, as described in the doc?
http://xgboost.readthedocs.io/en/latest/build.html
As in this answer:
Feature Importance with XGBClassifier
There always seems to be a problem with the pip-installation and xgboost. Building and installing it from your build seems to help.
This worked for me:
model.get_booster().get_score(importance_type='weight')
hope it helps
This is useful for you,maybe.
xgb.plot_importance(bst)
And this is the link:plot
I have written a very simple piece of code to try and print the synonyms associated with a word.
import nltk
from nltk.corpus import wordnet as wn
wordNetSynset = wn.synsets('small')
for synSet in wordNetSynset:
for synWords in synSet.lemma_names:
synonymList.add(synWords)
print synonymList
However, I get the following error:
Traceback (most recent call last):
File "test.py", line 6, in <module>
for synWords in synSet.lemma_names:
TypeError: 'instancemethod' object is not iterable
Does anyone know what the problem could be?
In Nltk 3, the lemma_names has been changed to a method from an attribute.
So you have to call the method
for synWords in synSet.lemma_names():
Other minor changes required are:
synonymList is not defined
List will not have an add method even if synonymList is defined
You better name your variable synonymSet
The generate method of nltk.text.Text seems to have been removed in NLTK 3.0.
For example:
>>> bible = nltk.corpus.gutenberg.words(u'bible-kjv.txt')
>>> bibleText = nltk.Text(bible)
>>> bibleText.generate()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Text' object has no attribute 'generate'
It may just be that I'm remembering wrongly how to do this, but everything I can find online seems to support the above method. Any ideas what I'm doing wrong?
A note in the first online chapter of the NLTK book says that:
The generate() method is not available in NLTK 3.0 but will be
reinstated in a subsequent version.