Duplicate from RisticksAI/ProfNet4
Browse filesCo-authored-by: - - - <ierhon@users.noreply.huggingface.co>
- .gitattributes +35 -0
- README.md +13 -0
- app.py +8 -0
- dataset.txt +41 -0
- embed_set.py +15 -0
- embedding.py +8 -0
- net.py +55 -0
- requirements.txt +4 -0
- start.py +31 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
35 |
+
discord-russian2.txt filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: ProfNet4
|
3 |
+
emoji: 🚀
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: red
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.27.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: RisticksAI/ProfNet4
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import start
|
3 |
+
|
4 |
+
def respond(message):
|
5 |
+
return start.generate(message)
|
6 |
+
|
7 |
+
iface = gr.Interface(fn=respond, inputs="text", outputs="text")
|
8 |
+
iface.launch()
|
dataset.txt
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
привет
|
2 |
+
Здравствуйте
|
3 |
+
Здравствуйте.
|
4 |
+
привет
|
5 |
+
Здравствуйте
|
6 |
+
Здравствуйте.
|
7 |
+
<null>
|
8 |
+
Кто вы?
|
9 |
+
Это тест Profnet4.
|
10 |
+
<null>
|
11 |
+
А зачем это?
|
12 |
+
Чтобы проверить работу этой идеи.
|
13 |
+
<null>
|
14 |
+
Какие недостатки идеи?
|
15 |
+
Долгое обучение и сама работа.
|
16 |
+
<null>
|
17 |
+
Что требуется улучшить в ProfNet4?
|
18 |
+
Скорее всего увеличить датасет и скорость работы, но скорость увеличится также если и использовать мощную видеокарту.
|
19 |
+
<null>
|
20 |
+
А где можно использовать ProfNet4?
|
21 |
+
Меня можно использовать как support chatbot на сайте, и в других случаях как ассистент, требуется просто изменить тренировочные данные.
|
22 |
+
<null>
|
23 |
+
А что ты можешь?
|
24 |
+
Отвечать на текстовое сообщение.
|
25 |
+
<null>
|
26 |
+
А ты можешь видеть или помнишь что я раньше писал?
|
27 |
+
Я вижу 3 сообщения назад.
|
28 |
+
<null>
|
29 |
+
Как тебя обучать?
|
30 |
+
На данный момент требуется изменить содержание файла dataset.txt
|
31 |
+
<null>
|
32 |
+
Как дела?
|
33 |
+
У меня всё хорошо, у вас?
|
34 |
+
Тоже всё отлично.
|
35 |
+
Можете мне задать вопрос, я готов ответить.
|
36 |
+
<null>
|
37 |
+
Почему ты так долго отвечаешь?
|
38 |
+
Во мне используется массивная нейросеть требующая долгое время для работы, при запуске на видеокарте всё будет работать гораздо быстрее.
|
39 |
+
<null>
|
40 |
+
Какие языки ты знаешь?
|
41 |
+
На данный момент я знаю Русский и Английский, но могу отвечать только на Русском языке.
|
embed_set.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
import embedding
|
3 |
+
from tqdm import tqdm
|
4 |
+
|
5 |
+
class SetLine:
|
6 |
+
def __init__(self, name):
|
7 |
+
self.name = name
|
8 |
+
self.inp = embedding.getvec(name)
|
9 |
+
|
10 |
+
net = []
|
11 |
+
with open("dataset.txt", "r") as f: lines = f.readlines()
|
12 |
+
for ind, i in tqdm(enumerate(lines[1:])):
|
13 |
+
if (i[:6] != "<null>"): net.append(SetLine(i))
|
14 |
+
|
15 |
+
with open("set.pckl", "wb") as f: pickle.dump(net, f)
|
embedding.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sentence_transformers import SentenceTransformer
|
2 |
+
|
3 |
+
model = SentenceTransformer('inkoziev/sbert_pq')
|
4 |
+
|
5 |
+
def getvec(text: str):
|
6 |
+
sentences = [text,]
|
7 |
+
embeddings = model.encode(sentences)
|
8 |
+
return embeddings[0]
|
net.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
import numpy as np
|
3 |
+
import tensorflow as tf
|
4 |
+
from tensorflow.keras.models import Sequential
|
5 |
+
from tensorflow.keras.layers import Dense, Dropout, Flatten, Input
|
6 |
+
from tensorflow.keras.optimizers import Adam
|
7 |
+
from tensorflow.keras.losses import MeanSquaredError
|
8 |
+
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
9 |
+
|
10 |
+
class SetLine:
|
11 |
+
def __init__(self, name, inp):
|
12 |
+
self.name = name
|
13 |
+
self.inp = embedding.getvec(name)
|
14 |
+
|
15 |
+
with open("set.pckl", "rb") as f:
|
16 |
+
dset = pickle.load(f)
|
17 |
+
|
18 |
+
sequences = [[x.inp for x in dset],]
|
19 |
+
|
20 |
+
vec_size = sequences[0][0].__len__()
|
21 |
+
|
22 |
+
window_size = 3
|
23 |
+
|
24 |
+
# Generate sliding windows and corresponding target vectors
|
25 |
+
sliding_windows = []
|
26 |
+
target_vectors = []
|
27 |
+
for seq in sequences:
|
28 |
+
for i in range(-window_size, len(seq) - window_size-1):
|
29 |
+
window = seq[i:i + window_size]
|
30 |
+
target = seq[i + window_size]
|
31 |
+
sliding_windows.append(np.array(window))
|
32 |
+
target_vectors.append(target)
|
33 |
+
|
34 |
+
# Pad sequences to a fixed length
|
35 |
+
max_seq_length = max(len(window) for window in sliding_windows)
|
36 |
+
padded_windows = pad_sequences(sliding_windows, maxlen=max_seq_length, padding='pre')
|
37 |
+
|
38 |
+
model = Sequential()
|
39 |
+
model.add(Input(shape=(max_seq_length, vec_size)))
|
40 |
+
model.add(Flatten())
|
41 |
+
model.add(Dense(512, activation='tanh'))
|
42 |
+
model.add(Dense(256, activation='tanh'))
|
43 |
+
model.add(Dense(512, activation='relu'))
|
44 |
+
model.add(Dense(300, activation='tanh'))
|
45 |
+
model.add(Dense(vec_size, activation='linear'))
|
46 |
+
|
47 |
+
# Compile the model
|
48 |
+
model.compile(optimizer=Adam(learning_rate=0.0001), loss=MeanSquaredError(), metrics=['accuracy'])
|
49 |
+
|
50 |
+
# Train the model
|
51 |
+
X = np.array(padded_windows)
|
52 |
+
y = np.array(target_vectors)
|
53 |
+
model.fit(X, y, epochs=128, batch_size=4)
|
54 |
+
|
55 |
+
model.save("net.h5")
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
sentence_transformers
|
2 |
+
numpy
|
3 |
+
tensorflow
|
4 |
+
keras
|
start.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import pickle
|
3 |
+
import embedding
|
4 |
+
import random
|
5 |
+
import embed_set
|
6 |
+
import net
|
7 |
+
from tqdm import tqdm
|
8 |
+
from tensorflow.keras.models import load_model
|
9 |
+
|
10 |
+
top_p = 1
|
11 |
+
|
12 |
+
class SetLine:
|
13 |
+
def __init__(self, name, inp):
|
14 |
+
self.name = name
|
15 |
+
self.inp = embedding.getvec(name)
|
16 |
+
|
17 |
+
with open("set.pckl", "rb") as f: dset = pickle.load(f)
|
18 |
+
|
19 |
+
model = load_model("net.h5")
|
20 |
+
|
21 |
+
def top_closest_vectors(input_vector, top_p=1):
|
22 |
+
distances = [(np.linalg.norm((neuron.inp - input_vector)), ind) for ind, neuron in enumerate(dset)]
|
23 |
+
closest_indices = sorted(distances, reverse=False, key=lambda x:x[0])[:top_p]
|
24 |
+
return closest_indices
|
25 |
+
|
26 |
+
def generate(text):
|
27 |
+
vecs = 3*[np.zeros(net.vec_size),] + [embedding.getvec(x) for x in text.split("\n")]
|
28 |
+
vecs = vecs[-3:]
|
29 |
+
vecs = np.array([vecs,])
|
30 |
+
rvec = model.predict(vecs)[0]
|
31 |
+
return dset[random.choice(top_closest_vectors(rvec))[1]].name
|