Commit 7b14a9fc authored by De Silva K.C.C.C's avatar De Silva K.C.C.C

bert usage

parent 05f26505
import nltk
import question_generator as q_gen
# nltk.download('words')
from bertopic import BERTopic
from nltk.corpus import words
model = BERTopic(verbose=True)
def get_topics(file):
topics_outputs = []
docs = []
with open(file) as file:
for line in file:
docs.append(line.rstrip())
topics, probabilities = model.fit_transform(docs)
#
print(model.get_topic_freq())
#
print('done')
#
# model.get_topic_freq().head(11)
print(model.get_topics())
for i in model.get_topic(0):
if i[0] in words.words():
pass
else:
print(i[0])
topics_outputs.append(i[0])
return topics_outputs
def get_topics_new(text):
topics = q_gen.get_keywords(text, q_gen.summarizer(text))
# print(topics)
return topics
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment