-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Model updated | 53번 채점을 LSA로 적용
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import numpy as np | ||
from sklearn.feature_extraction.text import TfidfVectorizer | ||
from sklearn.decomposition import TruncatedSVD | ||
from sklearn.metrics.pairwise import cosine_similarity | ||
from PyKomoran import * #형태소 분석기 변경 | ||
|
||
tfidf_vectorizer = TfidfVectorizer() | ||
komoran = Komoran('STABLE') | ||
|
||
def lsa_Similar(contents, answer): | ||
test = (komoran.get_plain_text(contents[0])).split(' ') | ||
for j in range(len(test)): | ||
temp = test[j].split('/') | ||
test[j] = temp[0] | ||
#print('여기',test) | ||
test = ' '.join(test) | ||
test2 = (komoran.get_plain_text(answer[0])).split(' ') | ||
for j in range(len(test2)): | ||
temp = test2[j].split('/') | ||
test2[j] = temp[0] | ||
#print('여기',test) | ||
test2 = ' '.join(test2) | ||
tfidf_vectorizer = TfidfVectorizer() | ||
tfidf_matrix = tfidf_vectorizer.fit_transform([test, test2]) | ||
|
||
# LSA를 사용하여 차원 축소 | ||
lsa = TruncatedSVD(n_components=2) | ||
lsa_matrix = lsa.fit_transform(tfidf_matrix) | ||
|
||
# 문장 간 유사도 계산 | ||
similarity_matrix = cosine_similarity(lsa_matrix) | ||
|
||
response = { | ||
'best_i': 0, | ||
'best_dist': 1 - similarity_matrix[1][0], | ||
'result': contents | ||
} | ||
|
||
print(similarity_matrix) | ||
return response |