Skip to content

Commit

Permalink
README.md 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
gunwoo45954 committed Mar 26, 2024
1 parent 8ce3f3a commit 7e521ed
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 24 deletions.
Binary file added Img/project_timeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Img/service_architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 29 additions & 23 deletions ML/AI_Poet/inference.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 3,
"metadata": {
"colab": {},
"colab_type": "code",
Expand All @@ -59,15 +59,15 @@
}
],
"source": [
"model = GPT2LMHeadModel.from_pretrained(\"gunwoo723/kogpt-trinity-poem-generator\").to(device)\n",
"model = GPT2LMHeadModel.from_pretrained(\"output/checkpoint-13000\").to(device)\n",
"tokenizer = PreTrainedTokenizerFast.from_pretrained(\"skt/ko-gpt-trinity-1.2B-v0.5\",\n",
" bos_token='<s>', eos_token='</s>', unk_token='<unk>',\n",
" pad_token='<pad>', mask_token='<mask>')"
]
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand All @@ -76,7 +76,7 @@
"Embedding(51201, 1920)"
]
},
"execution_count": 23,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -88,23 +88,25 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"sentence = '<s>멈춰버린 시계 속 마지막으로 남은 바램\\n'\n",
"sentence = '<s>떠나간 봄날의 설레는 기다림\\n'\n",
"inputs = tokenizer.encode(sentence, add_special_tokens=True, return_tensors='pt').to(device)\n",
"\n",
"with torch.no_grad():\n",
" output = model.generate(\n",
" input_ids=inputs,\n",
" temperature=0.5, # 생성 다양성 조절\n",
" min_length=32, # 생성되는 문장의 최소 길이\n",
" temperature=0.6, # 생성 다양성 조절\n",
" min_length=64, # 생성되는 문장의 최소 길이\n",
" max_length=256, # 생성되는 문장의 최대 길이\n",
" repetition_penalty=1.2, # 반복을 줄이는 패널티\n",
" do_sample=True, # 샘플링 기반 생성 활성화\n",
" early_stopping=True, # EOS token을 만나면 조기 종료\n",
" eos_token_id=tokenizer.eos_token_id\n",
" eos_token_id=tokenizer.eos_token_id,\n",
" top_k=10,\n",
" top_p=0.95\n",
" )\n",
"\n",
"generated_sequence = output[0].tolist()\n",
Expand All @@ -113,7 +115,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -122,28 +124,32 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 37,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"멈춰버린 시계 속 마지막으로 남은 바램\n",
"다시 돌아 올 수 없는 그 먼 곳 까지\n",
"떠나간 봄날의 설레는 기다림\n",
"그리움으로 다시 찾아온 봄의 향기\n",
"\n",
"홀로 타향에서 애타게 그리워 하는 \n",
"잊혀 진 기억속으로 한 걸음 다가서는 이\n",
"바람에 실려 오는 향수 묻어난다\n",
"그 옛날 보릿고개 넘을 때 \n",
"마지막 이었던 매화꽃 피던 날\n",
"가슴에 살며시 물결치는 그리움\n",
"\n",
"세월의 더께 묻어 둔 채 흘러간 추억들\n",
"아쉬운 눈길로 다시금 불러 보는 이름\n",
"이제 다시 볼 수 없음에 서러워라\n",
"새봄이 돌아오면 꽃잎은 더 푸르고\n",
"살랑이는 봄바람 불 때면 옛 추억에\n",
"잠겨오는 아련한 첫사랑의 연가\n",
"\n",
"잊힌 기억마저도 되살려 주는 시간들이\n",
"갈색 낙엽으로 쌓여만 가는 어느 가을날\n",
"한없이 깊어져간 가슴속 사연들을\n",
"낙엽따라 떠나가는 하얀 눈송이처럼 날려보낸다\n"
"목련의 고귀한 순결함처럼\n",
"그대의 따사한 눈길 속에 피는\n",
"곱디 고운 사랑의 미로\n",
"\n",
"춘삼월엔 맘 속 깊숙하게 파고드는\n",
"아름다운 사랑 노래하고픈데\n",
"보리피리 만들어 부르면서\n",
"첫사랑의 향연 그리워하네\n"
]
}
],
Expand Down
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,52 @@
#
# 오늘의 시

사용자의 감정을 물어보고 이를 활용해 시와 이미지를 생성하는 웹 서비스입니다. 이를 통해 자신의 감정을 풍요롭게 표현해보고, 문학적 표현을 통해 느끼는 감정을 더 깊게 이해할 수 있습니다. 그리고 SNS에 자신의 시와 이미지를 쉽게 공유해보며 서로의 생각을 나눠볼 수 있습니다.

인스타그램 공식 계정 [오늘의 시(@poemoftoday)](https://www.instagram.com/poemoftoday)에 게시물이 업로드됩니다.

__서비스 주소 :__ http://www.poemoftoday.shop

## 프로젝트 타임라인
![Alt text](Img/project_timeline.png)

## 팀원 소개
- 김기호_T6013 : 문장 데이터 생성, 문장 생성 모델 학습, Frontend
- 박상기_T6057 : 문장 데이터 생성, Frontend
- 심재혁_T6093 : 문장 데이터 생성, Backend, 배포
- 김건우_T6197 : 시 데이터 크롤링 및 전처리, 시 생성 모델 학습

## 서비스 구조 및 기능
![Alt text](Img/service_architecture.png)
### 1. 문학적 표현 문장 생성
- 사용자가 선택한 감정을 기반으로 문학적 표현이 담긴 문장을 생성합니다.
- 선택할 수 있는 감정은 크게 5가지로 각 카테고리에 4개의 단어가 존재합니다.
- 총 3개의 문장을 생성하며, 사용자는 1개를 선택할 수 있습니다.
- 기쁨 : "기쁘다", "즐겁다", "감사하다", "행복하다"
- 설레임 : "수줍다", "부끄럽다", "쑥쓰럽다", "민망하다"
- 슬픔 : "슬프다", "서럽다", "속상하다", "우울하다"
- 그리움 : "그립다", "공허하다", "외롭다", "후회스럽다"
- 불안 : "두렵다", "불안하다", "초조하다", "혼란스럽다"

### 2. 시, 이미지 생성
- 위에서 생성한 문장을 첫 행으로 하는 시를 생성합니다.
- 시를 생성할 때, 시의 구조와 전체적인 주제 흐름을 고려합니다.
- 그림은 첫 행에서 드러나는 감정과 분위기를 기반으로 생성됩니다.
- 그림체는 수채화를 사용합니다.

### 3. SNS 공유
- 생성된 시와 이미지를 인스타그램에 공유할 수 있습니다.
- 저희 프로젝트 공식 계정 "오늘의 시"에 게시물이 업로드됩니다.
- 공유할 때, 사용자의 인스타그램 ID를 입력해야하며 이는 게시물의 태그로 지정됩니다.
- 입력하신 인스타그램 ID가 존재하지 않는 경우에는 업로드할 수 없습니다.

## 로컬 실행방법
1. 라이브러리 설치
- 아래의 명령어를 사용해 라이브러리를 설치합니다.

pip install -r requirements.txt

2. app.py 실행
- 아래의 명령어를 사용해 서버를 실행합니다.

cd Application/
python3 app.py

0 comments on commit 7e521ed

Please sign in to comment.