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

TypeError: '<' not supported between instances of 'BeamSearchNode' and 'BeamSearchNode' #3

Open
gionanide opened this issue Oct 18, 2019 · 2 comments

Comments

@gionanide
Copy link

gionanide commented Oct 18, 2019

I had this problem. I found out that this happens when in the PriorityQueue(PQ) two elements have the same value then, the algorithm moves to the element itself. Because the element in the PQ is an object it generates this Error.

The solution was that I add in the class a special function to handle this by choosing the element with the highest probability., as follows. If this seems ok to you, you can add this lines in your code. Or I can make a pull request.

#function in the class BeamSearchNode
def __lt__(self, other):
        return self.prob < other.prob
@gionanide gionanide changed the title Test TypeError: '<' not supported between instances of 'BeamSearchNode' and 'BeamSearchNode' TypeError: '<' not supported between instances of 'BeamSearchNode' and 'BeamSearchNode' Oct 18, 2019
@RunxinXu
Copy link

@gionanide Hey bro,I think this is the property of the class "PriorityQueue". If you want to use it with the class you define by yourself, you may want to override the it method. Anyway, just some supplement~

@kennethjmyers
Copy link

Thanks, I was getting this issue too. On python 3.7 and the current version of the code I had to change this method to:

def __lt__(self, other):
        return self.logp < other.logp

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

3 participants