Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

TypeError: unsupported operand type(s) for +: 'int' and 'str' #21

Copy link
Copy link
@masayas

Description

@masayas
Issue body actions

I see the following error when running ch04/blei_lda.py

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-5511c9e27cd2> in <module>()
     37 for ti in range(model.num_topics):
     38     words = model.show_topic(ti, 64)
---> 39     tf = sum(f for f, w in words)
     40     with open('topics.txt', 'w') as output:
     41         output.write('\n'.join('{}:{}'.format(w, int(1000. * f / tf)) for f, w in words))

TypeError: unsupported operand type(s) for +: 'int' and 'str'

I think, since the frequency, f, and word, w, are the opposite on words, did you want to write w, f in words instead, as in the following?

     39     tf = sum(f for w, f in words)
     40     with open('topics.txt', 'w') as output:
     41         output.write('\n'.join('{}:{}'.format(w, int(1000. * f / tf)) for w, f in words))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.