Skip to content

Commit 1343fc1

Browse files
author
Arun Kirubarajan
authored
Create assignment2.py
1 parent 24ee354 commit 1343fc1

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

assignment2/assignment2.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import numpy as np
2+
import pandas as pd
3+
from collections import defaultdict
4+
5+
6+
def scavenger_hunt() -> dict:
7+
pass
8+
9+
10+
def get_words(file_path) -> list:
11+
pass
12+
13+
14+
def get_ngrams(words, size) -> list:
15+
pass
16+
17+
18+
def get_counts(n_grams) -> dict:
19+
pass
20+
21+
22+
def generate_gram(counts, context) -> str:
23+
pass
24+
25+
26+
def generate_sentence(counts, context, length=10) -> list:
27+
pass
28+
29+
30+
def stringify(sentence) -> list:
31+
return " ".join(" ".join(gram) for gram in sentence)
32+
33+
34+
if __name__ == '__main__':
35+
# create model
36+
words = get_words('corpus.txt')
37+
n_grams = get_ngrams(words, 1)
38+
counts = get_counts(n_grams)
39+
40+
# generate text
41+
context = n_grams[np.random.choice(len(n_grams))]
42+
sentence = generate_sentence(counts, context, length=50)
43+
print(stringify(sentence))

0 commit comments

Comments
 (0)