Tekkonetes commited on
Commit
e088236
·
1 Parent(s): b26eb37
Files changed (6) hide show
  1. README.md +0 -9
  2. corpus.txt +0 -0
  3. predict.py +24 -0
  4. pytorch_model.bin +0 -3
  5. requirements.txt +2 -0
  6. train.py +26 -0
README.md DELETED
@@ -1,9 +0,0 @@
1
- ---
2
- language: py
3
- library_name: PyTorch
4
- pipeline_tag: text-generation
5
- tags:
6
- - pytorch
7
- - text2text
8
- - tekkonetes
9
- ---
 
 
 
 
 
 
 
 
 
 
corpus.txt ADDED
File without changes
predict.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import libraries
2
+ import nltk
3
+ import numpy as np
4
+ import pickle
5
+ nltk.download('punkt')
6
+ # Define predict_word function
7
+ def predict_word(model, last_word):
8
+ if last_word in model:
9
+ return np.random.choice(model[last_word])
10
+ else:
11
+ return None
12
+ # Load the model
13
+ with open("model.pkl", "rb") as f:
14
+ model = pickle.load(f)
15
+
16
+ # Run the prediction for 10 words
17
+ input_words = input('Input words: ')
18
+ for i in range(10):
19
+ input_words_list = nltk.word_tokenize(input_words)
20
+ last_word = input_words_list[-1]
21
+ predicted_word = predict_word(model, last_word)
22
+ input_words = f"{input_words}" + " " + f'{predicted_word}'
23
+
24
+ print(input_words)
pytorch_model.bin DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:a4d1d24b0310816195ff64dfb22d22ea033844dc332f0c2bbc53a0af421483c3
3
- size 15748927
 
 
 
 
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ nltk==3.8.1
2
+ numpy==1.24.2
train.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Download nltk and numpy
2
+ import os
3
+ os.system('pip install nltk numpy')
4
+ import nltk
5
+ import numpy as np
6
+
7
+ nltk.download('punkt')
8
+ def train_model(corpus):
9
+ tokens = nltk.word_tokenize(corpus)
10
+ model = {}
11
+ for i in range(len(tokens) - 1):
12
+ if tokens[i] in model:
13
+ model[tokens[i]].append(tokens[i + 1])
14
+ else:
15
+ model[tokens[i]] = [tokens[i + 1]]
16
+ return model
17
+
18
+ import pickle
19
+
20
+ # Train the model on a given corpus
21
+ corpus = open('corpus.txt').read()
22
+ model = train_model(corpus)
23
+
24
+ # Save the model to a file
25
+ with open("model.pkl", "wb") as f:
26
+ pickle.dump(model, f)