<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Anomalies
Compare two groups of texts
Step1:  Categories
See how well a set of documents matches a set of categories.
As a rule of thumb, a score >= 0.4 means a weak match. Anything below 0.4 is noise.
Soon there will be an additional endpoint that can be trained.
Step2:  Clusters
Step3:  Counts
Step4:  Entities
Extract named entities from docs. You will get a list of entities for each doc.
Entities can be 'geo', 'person', 'org', or 'heuristics'.
Heuristics means that entities that we have seen before are returned,
even though we do not know what kind of entity it is.
Step5:  Sentiment
Step6:  Topics
Step7:  Wordcloud
<ASSISTANT_TASK:>
Python Code:
# A few sample short texts with user comments on two Facebook pages
texts_telia = json.load(open('texts_telia.json', 'r'))
texts_tele2 = json.load(open('texts_tele2.json', 'r'))
res_anomalies = bw.anomalies(texts_telia, texts_tele2, max_words=10, min_score=1)
pprint(res_anomalies)
Explanation: Anomalies
Compare two groups of texts
End of explanation
category_texts = [
    'Denna text handlar om pengar och dollar och ekonomi',
    'Denna text handlar om hamburgare, vitlök och grönsaker',
    'Här är en till text om mat och tomater'
]
categories = [
    ['ekonomi', 'valuta'],
    ['mat', 'matvaror', 'frukt', 'grönsaker'],
    ['djur', 'hund']
]
res_cat = bw.categories(category_texts, categories)
pprint(res_cat)
Explanation: Categories
See how well a set of documents matches a set of categories.
As a rule of thumb, a score >= 0.4 means a weak match. Anything below 0.4 is noise.
Soon there will be an additional endpoint that can be trained.
End of explanation
res_clusters = bw.clusters(texts_tele2, min_cluster_size=10)
pprint(res_clusters)
# Print a description of first cluster and all docs that belong to it
print(res_clusters['descriptions'][0])
first_cluster = [doc for doc, cluster in zip(texts_tele2, res_clusters['clusters']) if cluster == 0]
for doc in first_cluster:
    print(doc)
Explanation: Clusters
End of explanation
res_counts = bw.counts(texts_tele2)
pprint(res_counts)
Explanation: Counts
End of explanation
docs = ['De två största städerna i Sverige är Stockholm och Göteborg',
        'Donald Trump är Barack Obamas efterträdare',
        'En stad i Frankrike är Lyon']
bw.entities(docs)
Explanation: Entities
Extract named entities from docs. You will get a list of entities for each doc.
Entities can be 'geo', 'person', 'org', or 'heuristics'.
Heuristics means that entities that we have seen before are returned,
even though we do not know what kind of entity it is.
End of explanation
docs_sentiment = [
    'Nej, det här var inte alls bra',
    'Detta är en bra mening, som visar på en helt fantastisk fantasi hos författaren'
]
res_sentiment = bw.sentiment(docs_sentiment)
pprint(res_sentiment)
Explanation: Sentiment
End of explanation
docs_topics = [
    'De två största städerna i Sverige är Stockholm och Göteborg, men Rävlanda är mest creddig',
    'Donald Trump är Barack Obamas efterträdare',
    'Jag gillar äpplen och päron och jag kan jämföra dem']
res_topics = bw.topics(docs_topics)
pprint(res_topics)
Explanation: Topics
End of explanation
cloud = bw.wordcloud(bw.counts(texts_tele2))
cloud
from IPython.display import Image
from IPython.core.display import HTML 
Image(url= cloud['url'])
Explanation: Wordcloud
End of explanation
<END_TASK>