Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is that enumerated loop in infer_country supposed to do? #84

Open
andreas-wolf opened this issue Aug 4, 2020 · 0 comments
Open

Comments

@andreas-wolf
Copy link

Sorry, I really do not understand this code:

for loc in proced:
feat = self.make_country_matrix(loc)
#print("feat:", feat)
#labels = loc['labels']
feat_list.append(feat)
#try:
# for each potential country...
for n, i in enumerate(feat_list):
labels = i['labels']
try:
prediction = self.country_model.predict(i['matrix']).transpose()[0]
ranks = prediction.argsort()[::-1]
labels = np.asarray(labels)[ranks]
prediction = prediction[ranks]
except ValueError:
print(traceback.print_exc())
prediction = np.array([0])
labels = np.array([""])
loc['country_predicted'] = labels[0]
loc['country_conf'] = prediction[0]
loc['all_countries'] = labels
loc['all_confidence'] = prediction

You're looping over a collection proced
For every entry you create a country matrix. Ok.
Which you append to a list. Why?
Then you loop over that list, FOR EVERY loc in proced, but you only use the last iteration of that loop to write it back to loc
Furthermore when spacy found a location which is not in geonames then i['matrix'] is an empty list and self.country_model.predict(i['matrix']) throws a ValueError. It might be wiser to test feat if it contains values before calling predict.

ac74475 added a commit to ac74475/mordecai that referenced this issue Sep 17, 2021
Updated the infer_country method to reduce the computational complexity and therefore improve the performance, this was also identified in openeventdata#84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant