Giter VIP home page Giter VIP logo

graph-nlu's Issues

How could i run this code section from this project?

So, i already tried to run your babi_dialogue_ridge.ipynb notebooks, and so far i do some trial and error, but i just can't seem to solve this part of your code :

import operator
import scipy
import sklearn

eval_data = dev_data
gold=[]
guess=[]

indeces = list(set(eval_data.index))
print('num instances', len(indeces))
mrr = 0.0
for eid in indeces:
sub = rdata[rdata.index == eid] # grab the RE for this scene
target = compute_target(sub) # compose the predictions of each word to a target vector
distances = [(v['rname'], scipy.spatial.distance.cosine(target,v.ix[start_col:])) for i,v in restaurants.iterrows()]
distances.sort(key=operator.itemgetter(1))
guess += [distances[0][0]]
d = list(zip(*distances))[0]
mrr += compute_mrr(d, sub.iloc[-1].ix['target'])
gold += [sub.iloc[-1].ix['target']] # all the rows in sub have the same matrix

when i run it, it will give me this:

AttributeError Traceback (most recent call last)
in ()
13 sub = rdata[rdata.index == eid] # grab the RE for this scene
14 target = compute_target(sub) # compose the predictions of each word to a target vector
---> 15 distances = [(v['rname'], scipy.spatial.distance.cosine(target,v.ix[start_col:])) for i,v in restaurants.iterrows()]
16 distances.sort(key=operator.itemgetter(1))
17 guess += [distances[0][0]]

in (.0)
13 sub = rdata[rdata.index == eid] # grab the RE for this scene
14 target = compute_target(sub) # compose the predictions of each word to a target vector
---> 15 distances = [(v['rname'], scipy.spatial.distance.cosine(target,v.ix[start_col:])) for i,v in restaurants.iterrows()]
16 distances.sort(key=operator.itemgetter(1))
17 guess += [distances[0][0]]

~\Anaconda3\lib\site-packages\scipy\spatial\distance.py in cosine(u, v, w)
742 # cosine distance is also referred to as 'uncentered correlation',
743 # or 'reflective correlation'
--> 744 return correlation(u, v, w=w, centered=False)
745
746

~\Anaconda3\lib\site-packages\scipy\spatial\distance.py in correlation(u, v, w, centered)
693 u = u - umu
694 v = v - vmu
--> 695 uv = np.average(u * v, weights=w)
696 uu = np.average(np.square(u), weights=w)
697 vv = np.average(np.square(v), weights=w)

~\Anaconda3\lib\site-packages\numpy\lib\function_base.py in average(a, axis, weights, returned)
1127 if weights is None:
1128 avg = a.mean(axis)
-> 1129 scl = avg.dtype.type(a.size/avg.size)
1130 else:
1131 wgt = np.asanyarray(weights)

AttributeError: 'float' object has no attribute 'dtype'

Help, anyone?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.