forked from mit-nlp/MITIE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
categorize_text.py
executable file
·32 lines (24 loc) · 1.01 KB
/
categorize_text.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python
#
# This example shows how to use MITIE's text_categorizer from Python.
#
#
import sys, os
# Make sure you put the mitielib folder into the python search path. There are
# a lot of ways to do this, here we do it programmatically with the following
# two statements:
parent = os.path.dirname(os.path.realpath(__file__))
sys.path.append(parent + '/../../mitielib')
from mitie import *
# We will have MITIE predict which of these two sentences express positive sentiments.
test_tokens = ["What","a","black","and","bad","day"]
test_tokens_2 = ["I","am","so","happy"]
# Load a pre-trained text categorizer. This model is generated by
# train_text_categorizer.py so run that example first to get the file.
cat = text_categorizer("new_text_categorizer.dat")
# Call the categorizer with a list of tokens, the response is a label (a string)
# and a score (a number) indicating the confidence of the categorizer
label, score = cat(test_tokens)
print(label,score)
label, score = cat(test_tokens_2)
print(label,score)