Commit
·
6c8a6af
1
Parent(s):
0f8cc40
Update README.md
Browse files
README.md
CHANGED
@@ -2,7 +2,6 @@ import atexit
|
|
2 |
import json
|
3 |
import os
|
4 |
import sys
|
5 |
-
from collections.abc import Generator
|
6 |
|
7 |
import nltk
|
8 |
import numpy as np
|
@@ -10,31 +9,29 @@ import pyttsx3
|
|
10 |
import spacy
|
11 |
import spacy as nlp
|
12 |
import speech_recognition as sr
|
|
|
13 |
import transformers
|
14 |
from nltk.corpus import stopwords
|
15 |
from nltk.stem import WordNetLemmatizer
|
16 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
17 |
-
from transformers import AutoTokenizer
|
18 |
-
from transformers import GPTNeoForCausalLM
|
19 |
-
from transformers import pipeline
|
20 |
-
|
21 |
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
22 |
|
23 |
-
import torch
|
24 |
-
print(torch.__version__)
|
25 |
-
|
26 |
|
27 |
|
28 |
-
model_path = spacy.util.get_package_path('en_core_web_sm')
|
29 |
-
print(model_path)
|
30 |
|
31 |
print("transformers version:", transformers.__version__)
|
32 |
print("spacy version:", spacy.__version__)
|
33 |
print("nltk version:", nltk.__version__)
|
34 |
|
|
|
|
|
|
|
|
|
35 |
|
|
|
|
|
36 |
|
37 |
-
sys.path.append(r"C:\Users\withe\PycharmProjects\no hope2\Gpt-Neo1")
|
38 |
|
39 |
# Download necessary NLTK resources
|
40 |
nltk.download('punkt')
|
@@ -42,7 +39,6 @@ nltk.download('stopwords')
|
|
42 |
nltk.download('wordnet')
|
43 |
nltk.download('omw-1.4')
|
44 |
|
45 |
-
|
46 |
# Load the spaCy model
|
47 |
nlp = spacy.load('en_core_web_sm')
|
48 |
|
@@ -52,7 +48,6 @@ text = "Example text to process"
|
|
52 |
# Process the text using the nlp object
|
53 |
doc = nlp(text)
|
54 |
|
55 |
-
|
56 |
# Extract named entities from the processed text
|
57 |
named_entities = []
|
58 |
for entity in doc.ents:
|
@@ -67,7 +62,7 @@ dotenv_path = './API_KEY.env'
|
|
67 |
(dotenv_path)
|
68 |
|
69 |
# Check if GPU is available and set the device accordingly
|
70 |
-
device = torch.device('cuda:
|
71 |
|
72 |
# Initialize the speech engine
|
73 |
speech_engine = pyttsx3.init()
|
@@ -109,9 +104,9 @@ class CommonModule:
|
|
109 |
self.name = name
|
110 |
self.param1 = param1
|
111 |
self.param2 = param2
|
112 |
-
self.tokenizer = AutoTokenizer.from_pretrained(
|
113 |
self.tokenizer.add_special_tokens({'pad_token': '[PAD]'})
|
114 |
-
self.gpt3_model =
|
115 |
self.gpt3_model.to(device) # Move model to the device (GPU or CPU)
|
116 |
self.memory_module = MemoryModule()
|
117 |
self.sentiment_module = SentimentAnalysisModule()
|
@@ -123,8 +118,6 @@ class CommonModule:
|
|
123 |
self.temperature = 0.3
|
124 |
self.response_cache = {} # Cache for storing frequently occurring responses
|
125 |
|
126 |
-
|
127 |
-
|
128 |
def reset_conversation(self):
|
129 |
self.memory_module.reset_memory()
|
130 |
|
@@ -135,18 +128,17 @@ class CommonModule:
|
|
135 |
return self.response_cache.get(entity)
|
136 |
return None
|
137 |
|
138 |
-
|
139 |
-
|
140 |
def generate_gpt3_response(self, input_text, conversation_history, temperature=0.3):
|
141 |
prompt = '\n'.join(conversation_history) + '\n' + input_text + '\n'
|
142 |
|
143 |
-
generator = pipeline('text-generation', model=
|
144 |
output = generator(
|
145 |
prompt,
|
146 |
do_sample=True,
|
147 |
-
min_length=
|
148 |
-
|
149 |
-
num_return_sequences=
|
|
|
150 |
)
|
151 |
|
152 |
if output:
|
@@ -332,7 +324,7 @@ def exit_handler(common_module):
|
|
332 |
'memory': common_module.memory_module.memory,
|
333 |
'named_entities': list(common_module.memory_module.named_entities)
|
334 |
}
|
335 |
-
common_module.save_memory('C:\\Users\\withe\\PycharmProjects\\
|
336 |
print("Memory data saved successfully.")
|
337 |
|
338 |
return memory_data
|
@@ -343,29 +335,22 @@ def check_memory_file(file_path):
|
|
343 |
return os.path.isfile(file_path)
|
344 |
|
345 |
|
|
|
346 |
if __name__ == "__main__":
|
347 |
-
model = '
|
348 |
name = "Chat bot1"
|
349 |
param1 = 'value1'
|
350 |
param2 = 'value2'
|
351 |
common_module = CommonModule(model, name, param1, param2)
|
352 |
|
353 |
-
memory_file_path = 'C:\\Users\\withe\\PycharmProjects\\
|
354 |
if check_memory_file(memory_file_path):
|
355 |
with open(memory_file_path, 'r') as file:
|
356 |
memory_data = json.load(file)
|
357 |
common_module.load_memory_data(memory_data)
|
358 |
|
|
|
359 |
atexit.register(exit_handler, common_module)
|
360 |
|
361 |
common_module.converse()
|
362 |
-
|
363 |
-
# Generate response using the generator
|
364 |
-
prompt = "EleutherAI has"
|
365 |
-
generated_text = Generator(prompt, do_sample=True, min_length=50)
|
366 |
-
|
367 |
-
if generated_text:
|
368 |
-
generated_response = generated_text[0]['generated_text'].strip()
|
369 |
-
print(generated_response)
|
370 |
-
|
371 |
-
common_module.save_memory(memory_file_path)
|
|
|
2 |
import json
|
3 |
import os
|
4 |
import sys
|
|
|
5 |
|
6 |
import nltk
|
7 |
import numpy as np
|
|
|
9 |
import spacy
|
10 |
import spacy as nlp
|
11 |
import speech_recognition as sr
|
12 |
+
import torch
|
13 |
import transformers
|
14 |
from nltk.corpus import stopwords
|
15 |
from nltk.stem import WordNetLemmatizer
|
16 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
17 |
+
from transformers import AutoTokenizer, GPTNeoForCausalLM, pipeline, AutoModelForCausalLM
|
|
|
|
|
|
|
18 |
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
19 |
|
|
|
|
|
|
|
20 |
|
21 |
|
|
|
|
|
22 |
|
23 |
print("transformers version:", transformers.__version__)
|
24 |
print("spacy version:", spacy.__version__)
|
25 |
print("nltk version:", nltk.__version__)
|
26 |
|
27 |
+
from transformers import AutoTokenizer
|
28 |
+
|
29 |
+
vocab_file = r"C:/Users/withe/PycharmProjects/no hope2/EleutherAI2/vocab.txt"
|
30 |
+
tokenizer = AutoTokenizer.from_pretrained("razerblade072611/EleutherAI2", vocab_file=vocab_file)
|
31 |
|
32 |
+
merges_file = r"C:/Users/withe/PycharmProjects/no hope2/EleutherAI2/merges.txt"
|
33 |
+
tokenizer = AutoTokenizer.from_pretrained("razerblade072611/EleutherAI2", merges_file=merges_file)
|
34 |
|
|
|
35 |
|
36 |
# Download necessary NLTK resources
|
37 |
nltk.download('punkt')
|
|
|
39 |
nltk.download('wordnet')
|
40 |
nltk.download('omw-1.4')
|
41 |
|
|
|
42 |
# Load the spaCy model
|
43 |
nlp = spacy.load('en_core_web_sm')
|
44 |
|
|
|
48 |
# Process the text using the nlp object
|
49 |
doc = nlp(text)
|
50 |
|
|
|
51 |
# Extract named entities from the processed text
|
52 |
named_entities = []
|
53 |
for entity in doc.ents:
|
|
|
62 |
(dotenv_path)
|
63 |
|
64 |
# Check if GPU is available and set the device accordingly
|
65 |
+
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
|
66 |
|
67 |
# Initialize the speech engine
|
68 |
speech_engine = pyttsx3.init()
|
|
|
104 |
self.name = name
|
105 |
self.param1 = param1
|
106 |
self.param2 = param2
|
107 |
+
self.tokenizer = AutoTokenizer.from_pretrained("razerblade072611/EleutherAI2") # Load the tokenizer
|
108 |
self.tokenizer.add_special_tokens({'pad_token': '[PAD]'})
|
109 |
+
self.gpt3_model = AutoModelForCausalLM.from_pretrained("razerblade072611/EleutherAI2")
|
110 |
self.gpt3_model.to(device) # Move model to the device (GPU or CPU)
|
111 |
self.memory_module = MemoryModule()
|
112 |
self.sentiment_module = SentimentAnalysisModule()
|
|
|
118 |
self.temperature = 0.3
|
119 |
self.response_cache = {} # Cache for storing frequently occurring responses
|
120 |
|
|
|
|
|
121 |
def reset_conversation(self):
|
122 |
self.memory_module.reset_memory()
|
123 |
|
|
|
128 |
return self.response_cache.get(entity)
|
129 |
return None
|
130 |
|
|
|
|
|
131 |
def generate_gpt3_response(self, input_text, conversation_history, temperature=0.3):
|
132 |
prompt = '\n'.join(conversation_history) + '\n' + input_text + '\n'
|
133 |
|
134 |
+
generator = pipeline('text-generation', model="razerblade072611/EleutherAI2")
|
135 |
output = generator(
|
136 |
prompt,
|
137 |
do_sample=True,
|
138 |
+
min_length=10,
|
139 |
+
max_length=50,
|
140 |
+
num_return_sequences=2,
|
141 |
+
temperature=0.3
|
142 |
)
|
143 |
|
144 |
if output:
|
|
|
324 |
'memory': common_module.memory_module.memory,
|
325 |
'named_entities': list(common_module.memory_module.named_entities)
|
326 |
}
|
327 |
+
common_module.save_memory('C:\\Users\\withe\\PycharmProjects\\no hope2\\Chat_Bot1\\save_memory.json')
|
328 |
print("Memory data saved successfully.")
|
329 |
|
330 |
return memory_data
|
|
|
335 |
return os.path.isfile(file_path)
|
336 |
|
337 |
|
338 |
+
# Modify the main section of the code to load memory data if the file exists
|
339 |
if __name__ == "__main__":
|
340 |
+
model = '"EleutherAI2"'
|
341 |
name = "Chat bot1"
|
342 |
param1 = 'value1'
|
343 |
param2 = 'value2'
|
344 |
common_module = CommonModule(model, name, param1, param2)
|
345 |
|
346 |
+
memory_file_path = 'C:\\Users\\withe\\PycharmProjects\\no hope2\\Chat_Bot1\\load_memory1.json'
|
347 |
if check_memory_file(memory_file_path):
|
348 |
with open(memory_file_path, 'r') as file:
|
349 |
memory_data = json.load(file)
|
350 |
common_module.load_memory_data(memory_data)
|
351 |
|
352 |
+
# Register the exit handler
|
353 |
atexit.register(exit_handler, common_module)
|
354 |
|
355 |
common_module.converse()
|
356 |
+
common_module.save_memory(memory_file_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|