ElijahDi commited on
Commit
4c8900e
1 Parent(s): d950774

Upload 3 files

Browse files
resources/corpus_embeddings_ms.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e0d2d9fe8e6c6d15b65b99674572ec8b6a94279bbc16c4c6d06a9244b2be19a1
3
+ size 32710365
resources/functions.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import string
3
+ import pandas as pd
4
+ import nltk
5
+ import pymorphy2
6
+ from nltk.corpus import stopwords
7
+ nltk.download('stopwords')
8
+ from sentence_transformers import util
9
+
10
+ stop_words = set(stopwords.words('russian'))
11
+ morph = pymorphy2.MorphAnalyzer()
12
+
13
+ def data_preprocessing_hard(text: str) -> str:
14
+ text = str(text)
15
+ text = text.lower()
16
+ text = re.sub('<.*?>', '', text)
17
+ text = re.sub(r'[^а-яА-Я\s]', '', text)
18
+ text = ''.join([c for c in text if c not in string.punctuation])
19
+ text = ' '.join([word for word in text.split() if word not in stop_words])
20
+ # text = ''.join([char for char in text if not char.isdigit()])
21
+ text = ' '.join([morph.parse(word)[0].normal_form for word in text.split()])
22
+ return text
23
+
24
+ def filter(df: pd.DataFrame, ganre_list: list):
25
+ filtered_df = df[df['ganres'].apply(lambda x: any(g in ganre_list for g in(x)))]
26
+ filt_ind = filtered_df.index.to_list()
27
+ return filt_ind
28
+
29
+ def recommend(model, text: str, embeddings, top_k):
30
+ query_embeddings = model.encode([text], convert_to_tensor=True)
31
+ embeddings = embeddings.to("cpu")
32
+ # embeddings = util.normalize_embeddings(embeddings)
33
+
34
+ query_embeddings = query_embeddings.to("cpu")
35
+ # query_embeddings = util.normalize_embeddings(query_embeddings)
36
+ hits = util.semantic_search(query_embeddings, embeddings, top_k=top_k)#, score_function=util.dot_score)
37
+ return hits
resources/parcing.ipynb ADDED
The diff for this file is too large to render. See raw diff