Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want to calculate the accuracy of this model that predicts the next word based on 3 previous words using n - gram. def generate

I want to calculate the accuracy of this model that predicts the next word based on 3 previous words using n-gram.
def generate_aya(start_phrase):
start = start_phrase
threshold = random.random()
aya =[]
while start not in ngrams.keys():
start_new = input(": ")
start = start_new
for i in range(1):
line = start
for j in range(3):
line_words = nltk.word_tokenize(line)
start =''.join(line_words[-n +3:])
candidates = ngrams.get(start,[])
if not candidates:
print(f"{start}")
break
probability =[candidates.count(word)/ len(candidates) for word in candidates]
accumulator =[sum(probability[:i +1]) for i in range(len(probability))]
for word, acc in zip(candidates, accumulator):
if acc >= threshold:
next_word = word
break
else:
next_word = random.choice(candidates)
line +=''+ next_word
aya.append(line)
start = random.choice(ngrams.get(start, list(ngrams.keys())))
return '
'.join(aya)
start_word = input(": ") # Prompt the user to enter a word to start the aya
#print('The ayah')
aya = generate_aya(start_word) # Generate the aya using the input word as the starting point
query =aya
search_results = retrieve_verse_information(query, dataset)
print(f"Text of the verse: {result['Document']}")
print(f"{result['Information']}")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

Identify the effects and dangers of using stimulants.

Answered: 1 week ago

Question

LO 14-7 What to do after an interview.

Answered: 1 week ago

Question

controls for cybersecurity include

Answered: 1 week ago