Skip to content

Commit

Permalink
feat: Model updated | 53번 채점을 LSA로 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
yujin37 committed Nov 3, 2023
1 parent 5ac60de commit b0f4446
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Model/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import re
from gpt_response import gpt_response
from lsa_Similar import lsa_Similar
from flask_cors import CORS
app = Flask(__name__) #상태 알아보기2
cors = CORS(app, resources={r"*": {"origins": "https://port-0-docker-essay-score-jvvy2blm7ipnj3.sel5.cloudtype.app"}})
Expand Down Expand Up @@ -279,7 +280,10 @@ def get_score():
return jsonify(response)
else:
#사용자 답안과 , 실제 답안 content, answer
similar = similarity(contents, answer)
if quest_num<=52:
similar = similarity(contents, answer)
else:
similar = lsa_Similar(contents,answer)
#사용자 답안 content
spell = pusan_univ_spell(contents)

Expand Down
40 changes: 40 additions & 0 deletions Model/lsa_Similar.py
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

0 comments on commit b0f4446

Please sign in to comment.