0

I'm using fastText implementation of the module gensim. Despite getting no reasons, my program throws an exception.

Here is the code:

try:
    data = []
    with open(TXT_PATH, 'r', encoding='utf-8') as txt_file:
        for line in txt_file:
            for part in line.split(' '):
                data.append(part.strip())

    fastText = FastText(data, min_count=1, size=10000, window=5, workers=4)

    # Print results
    word_1 = 'happy'
    word_2 = 'birthday'
    print(f'Similarity between {word_1} and {word_2} thru fastText: {fastText.similarity(word_1, word_2)}')
except Exception as err:
    print(f'\n!!!!! An error happened! Detail: {str(err)}')

The end of the output:

!!!!! An error happened! Detail: 
talha06
  • 6,206
  • 21
  • 92
  • 147

1 Answers1

0

Per my answer on your other question, your data doesn't appear to be in the right format (where each item is a list-of-strings), and size=10000 is far outside of the usual range of sensible vector-sizes.

But mainly, if you want more exception info, you shouldn't be catching Exception and printing your own minimal, cryptic error message. Remove the try/except handling from your code, run it again, and you should see a more helpful error message, including a call stack which shows exactly which line of your code (and lines of called library code) are involved in the error condition.

If that alone doesn't guide you to fix the issue, you could add the extra details of the full error & call stack to your question to help others see what's happening.

gojomo
  • 52,260
  • 14
  • 86
  • 115
  • 1
    Thank you very much for your valuable contribution. Yes, when I have removed the `try-except` handling, I got a helpful error stacktrace. So, last question, how can I get the full error stacktrace with using `try-except` handling? – talha06 Nov 01 '19 at 23:42
  • 1
    You can see some ideas at – but broad exception-catching of errors you don't yet understand (as opposed to expected exceptions) is often a bad idea, compared to allowing the default display/halt to occur. – gojomo Nov 01 '19 at 23:50