Skip to main content

An explainable styler for the Korean language

Project description

Politely

PyPI version Open in Streamlit Open In Colab Code style: black Hits Downloads Downloads

A rule-based politeness styler for the Korean language
image

Quick Start ๐Ÿš€

1๏ธโƒฃ Install politely

pip3 install politely

2๏ธโƒฃ Split your text into sentences

Split your text into sentences with whatever tools you prefer. Here, we use kiwipiepy for the sake of demonstration:

from kiwipiepy import Kiwi
# an excerpt from ๋™๋ฐฑ๊ฝƒ (๊น€์œ ์ •)
text = """์ž”์†Œ๋ฆฌ๋ฅผ ๋‘๋ฃจ ๋Š˜์–ด๋†“๋‹ค๊ฐ€ ๋‚จ์ด ๋“ค์„๊นŒ๋ด ์†์œผ๋กœ ์ž…์„ ํ‹€์–ด๋ง‰๊ณ ๋Š” ๊ทธ ์†์—์„œ ๊น”๊น”๋Œ„๋‹ค. ๋ณ„๋กœ ์šฐ์Šค์šธ ๊ฒƒ๋„ ์—†๋Š”๋ฐ ๋‚ ์”จ๊ฐ€ ํ’€๋ฆฌ๋”๋‹ˆ ์ด ๋†ˆ์˜ ๊ณ„์ง‘์• ๊ฐ€ ๋ฏธ์ณค๋‚˜ ํ•˜๊ณ  ์˜์‹ฌํ•˜์˜€๋‹ค.
๊ฒŒ๋‹ค๊ฐ€ ์กฐ๊ธˆ ๋’ค์—๋Š” ์ œ ์ง‘๊ป˜๋ฅผ ํ• ๊ธˆํ• ๊ธˆ ๋Œ์•„๋ณด๋”๋‹ˆ ํ–‰์ฃผ์น˜๋งˆ์˜ ์†์œผ๋กœ ๊ผˆ๋˜ ๋ฐ”๋ฅธ์†์„ ๋ฝ‘์•„์„œ ๋‚˜์˜ ํ„ฑ๋ฐ‘์œผ๋กœ ๋ถˆ์‘ฅ ๋‚ด๋ฏธ๋Š” ๊ฒƒ์ด๋‹ค. 
์–ธ์ œ ๊ตฌ์› ๋Š”์ง€ ๋”์šด ๊น€์ด ํ™ฑ ๋ผ์น˜๋Š” ๊ตต์€ ๊ฐ์ž ์„ธ ๊ฐœ๊ฐ€ ์†์— ๋ฟŒ๋“ฏ์ด ์ฅ์˜€๋‹ค. "๋Š ์ง‘์—” ์ด๊ฑฐ ์—†์ง€?" ํ•˜๊ณ  ์ƒ์ƒ‰์žˆ๋Š” ํฐ์†Œ๋ฆฌ๋ฅผ ํ•˜๊ณ ๋Š” ์ œ๊ฐ€ ์ค€ ๊ฒƒ์„ ๋‚จ์ด ์•Œ๋ฉด์€ ํฐ์ผ๋‚ ํ…Œ๋‹ˆ ์—ฌ๊ธฐ์„œ ์–ผ๋ฅธ ๋จน์–ด ๋ฒ„๋ฆฌ๋ž€๋‹ค.
๊ทธ๋ฆฌ๊ณ  ๋˜ ํ•˜๋Š” ์†Œ๋ฆฌ๊ฐ€, "๋„ˆ ๋ด„๊ฐ์ž๊ฐ€ ๋ง›์žˆ๋‹จ๋‹ค." "๋‚œ ๊ฐ์ž ์•ˆ ๋จน๋Š”๋‹ค. ๋„ˆ๋‚˜ ๋จน์–ด๋ผ." ๋‚˜๋Š” ๊ณ ๊ฐœ๋„ ๋Œ๋ฆฌ์ง€ ์•Š๊ณ  ์ผํ•˜๋˜ ์†์œผ๋กœ ๊ทธ ๊ฐ์ž๋ฅผ ๋„๋กœ ์–ด๊นจ ๋„ˆ๋จธ๋กœ ์‘ฅ ๋ฐ€์–ด ๋ฒ„๋ ธ๋‹ค.
๊ทธ๋žฌ๋”๋‹ˆ ๊ทธ๋ž˜๋„ ๊ฐ€๋Š” ๊ธฐ์ƒ‰์ด ์—†๊ณ , ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์Œ”๊ทผ์Œ”๊ทผํ•˜๊ณ  ์‹ฌ์ƒ์น˜ ์•Š๊ฒŒ ์ˆจ์†Œ๋ฆฌ๊ฐ€ ์ ์  ๊ฑฐ์น ์–ด์ง„๋‹ค. ์ด๊ฑด ๋˜ ๋ญ์•ผ ์‹ถ์–ด์„œ ๊ทธ๋•Œ์—์•ผ ๋น„๋กœ์†Œ ๋Œ์•„๋‹ค๋ณด๋‹ˆ ๋‚˜๋Š” ์ฐธ์œผ๋กœ ๋†€๋ž๋‹ค.
์šฐ๋ฆฌ๊ฐ€ ์ด ๋™๋„ค์— ๋“ค์–ด์˜จ ๊ฒƒ์€ ๊ทผ ์‚ผ๋…„์งธ ๋˜์–ด์˜ค์ง€๋งŒ ์—ฌํƒœ๊ป ๊ฐ€๋ฌด์žก์žกํ•œ ์ ์ˆœ์ด์˜ ์–ผ๊ตด์ด ์ด๋ ‡๊ฒŒ๊นŒ์ง€ ํ™๋‹น๋ฌด์ฒ˜๋Ÿผ ์ƒˆ๋นจ๊ฐœ์ง„ ๋ฒ•์ด ์—†์—ˆ๋‹ค.
๊ฒŒ๋‹ค๊ฐ€ ๋ˆˆ์— ๋…์„ ์˜ฌ๋ฆฌ๊ณ  ํ•œ์ฐธ ๋‚˜๋ฅผ ์š”๋ ‡๊ฒŒ ์˜์•„๋ณด๋”๋‹ˆ ๋‚˜์ค‘์—๋Š” ๋ˆˆ๋ฌผ๊นŒ์ง€ ์–ด๋ฆฌ๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ƒ.
๊ทธ๋ฆฌ๊ณ  ๋ฐ”๊ตฌ๋‹ˆ๋ฅผ ๋‹ค์‹œ ์ง‘์–ด๋“ค๋”๋‹ˆ ์ด๋ฅผ ๊ผญ ์•…๋ฌผ๊ณ ๋Š” ์—Ž์–ด์งˆ ๋“ฏ ์ž๋น ์งˆ ๋“ฏ ๋…ผ๋‘‘์œผ๋กœ ํšกํ•˜๊ฒŒ ๋‹ฌ์•„๋‚˜๋Š” ๊ฒƒ์ด๋‹ค."""
kiwi = Kiwi()
sents = [sent.text.strip() for sent in kiwi.split_into_sents(text)]

3๏ธโƒฃ Speak politely with Styler

Instantiate an object of Styler, and style your sentences in a polite or formal manner with it:

from politely import Styler
from pprint import pprint
styler = Styler()
pprint(" ".join([styler(sent, 1) for sent in sents]))  # 1 = polite
('์ž”์†Œ๋ฆฌ๋ฅผ ๋‘๋ฃจ ๋Š˜์–ด๋†“๋‹ค๊ฐ€ ๋‚จ์ด ๋“ค์„๊นŒ ๋ด ์†์œผ๋กœ ์ž…์„ ํ‹€์–ด๋ง‰๊ณ ๋Š” ๊ทธ ์†์—์„œ ๊น”๊น”๋Œ€์š”. ๋ณ„๋กœ ์šฐ์Šค์šธ ๊ฒƒ๋„ ์—†๋Š”๋ฐ ๋‚ ์”จ๊ฐ€ ํ’€๋ฆฌ๋”๋‹ˆ ์ด ๋†ˆ์˜ '
 '๊ณ„์ง‘์• ๊ฐ€ ๋ฏธ์ณค๋‚˜ ํ•˜๊ณ  ์˜์‹ฌํ–ˆ์–ด์š”. ๊ฒŒ๋‹ค๊ฐ€ ์กฐ๊ธˆ ๋’ค์—๋Š” ์ œ ์ง‘๊ป˜๋ฅผ ํ•  ๊ธˆํ•  ๊ธˆ ๋Œ์•„๋ณด๋”๋‹ˆ ํ–‰์ฃผ์น˜๋งˆ์˜ ์†์œผ๋กœ ๊ผˆ๋˜ ๋ฐ”๋ฅธ ์†์„ ๋ฝ‘์•„์„œ ์ œ ํ„ฑ '
 '๋ฐ‘์œผ๋กœ ๋ถˆ์‘ฅ ๋‚ด๋ฏธ๋Š” ๊ฒŒ์—์š”. ์–ธ์ œ ๊ตฌ์› ๋Š”์ง€ ๋”์šด ๊น€์ด ํ™ฑ ๋ผ์น˜๋Š” ๊ตต์€ ๊ฐ์ž ์„ธ ๊ฐœ๊ฐ€ ์†์— ๋ฟŒ๋“ฏ์ด ์ฅ์˜€์–ด์š”. "๋Š ์ง‘์—๋Š” ์ด ๊ฑฐ ์—†์ฃ ? '
 '"ํ•˜๊ณ  ์ƒ์ƒ‰ ์žˆ๋Š” ํฐ ์†Œ๋ฆฌ๋ฅผ ํ•˜๊ณ ๋Š” ์ œ๊ฐ€ ์ค€ ๊ฒƒ์„ ๋‚จ์ด ์•Œ๋ฉด์€ ํฐ์ผ ๋‚  ํ…Œ๋‹ˆ ์—ฌ๊ธฐ์„œ ์–ผ๋ฅธ ๋จน์–ด ๋ฒ„๋ฆฌ๋ž˜์š”. ๊ทธ๋ฆฌ๊ณ  ๋˜ ํ•˜๋Š” ์†Œ๋ฆฌ๊ฐ€,"๋‹น์‹  '
 '๋ด„ ๊ฐ์ž๊ฐ€ ๋ง›์žˆ์–ด์š”. ""๋‚œ ๊ฐ์ž ์•ˆ ๋จน์–ด์š”. ๋‹น์‹ ์ด๋‚˜ ๋จน์–ด์š”. "์ €๋Š” ๊ณ ๊ฐœ๋„ ๋Œ๋ฆฌ์ง€ ์•Š๊ณ  ์ผํ•˜๋˜ ์†์œผ๋กœ ๊ทธ ๊ฐ์ž๋ฅผ ๋„๋กœ ์–ด๊นจ ๋„ˆ๋จธ๋กœ ์‘ฅ '
 '๋ฐ€์–ด ๋ฒ„๋ ธ์–ด์š”. ๊ทธ๋žฌ๋”๋‹ˆ ๊ทธ๋ž˜๋„ ๊ฐ€๋Š” ๊ธฐ์ƒ‰์ด ์—†๊ณ , ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์Œ”๊ทผ์Œ”๊ทผํ•˜๊ณ  ์‹ฌ์ƒํ•˜์ง€ ์•Š๊ฒŒ ์ˆจ์†Œ๋ฆฌ๊ฐ€ ์ ์  ๊ฑฐ์น ์–ด์ ธ์š”. ์ด๊ฑฐ๋Š” ๋˜ ๋ญ์•ผ '
 '์‹ถ์–ด์„œ ๊ทธ ๋•Œ์—์•ผ ๋น„๋กœ์†Œ ๋Œ์•„๋‹ค๋ณด๋‹ˆ ์ €๋Š” ์ฐธ์œผ๋กœ ๋†€๋ž์–ด์š”. ์ €ํฌ๊ฐ€ ์ด ๋™๋„ค์— ๋“ค์–ด์˜จ ๊ฒƒ์€ ๊ทผ ์‚ผ ๋…„์งธ ๋ผ ์˜ค์ง€๋งŒ ์—ฌํƒœ๊ป ๊ฐ€๋ฌด์žก์žกํ•œ ์ ์ˆ˜๋Š” '
 '์ด์˜ ์–ผ๊ตด์ด ์ด๋ ‡๊ฒŒ๊นŒ์ง€ ํ™๋‹น๋ฌด์ฒ˜๋Ÿผ ์ƒˆ๋นจ๊ฐœ์ง„ ๋ฒ•์ด ์—†์—ˆ์–ด์š”. ๊ฒŒ๋‹ค๊ฐ€ ๋ˆˆ์— ๋…์„ ์˜ฌ๋ฆฌ๊ณ  ํ•œ์ฐธ ์ €๋ฅผ ์š”๋ ‡๊ฒŒ ์˜์•„๋ณด๋”๋‹ˆ ๋‚˜์ค‘์—๋Š” ๋ˆˆ๋ฌผ๊นŒ์ง€ ์–ด๋ฆฌ๋Š” '
 '๊ฒŒ ์•„๋…€์š”. ๊ทธ๋ฆฌ๊ณ  ๋ฐ”๊ตฌ๋‹ˆ๋ฅผ ๋‹ค์‹œ ์ง‘์–ด ๋“ค๋”๋‹ˆ ์ด๋ฅผ ๊ผญ ์•…๋ฌผ๊ณ ๋Š” ์—Ž์–ด์งˆ ๋“ฏ ์ž๋น ์งˆ ๋“ฏ ๋…ผ๋‘‘์œผ๋กœ ํšกํ•˜๊ฒŒ ๋‹ฌ์•„๋‚˜๋Š” ๊ฒŒ์—์š”.')
pprint(" ".join([styler(sent, 2) for sent in sents]))  # 2 = formal
('์ž”์†Œ๋ฆฌ๋ฅผ ๋‘๋ฃจ ๋Š˜์–ด๋†“๋‹ค๊ฐ€ ๋‚จ์ด ๋“ค์„๊นŒ ๋ด ์†์œผ๋กœ ์ž…์„ ํ‹€์–ด๋ง‰๊ณ ๋Š” ๊ทธ ์†์—์„œ ๊น”๊น”๋Œ‘๋‹ˆ๋‹ค. ๋ณ„๋กœ ์šฐ์Šค์šธ ๊ฒƒ๋„ ์—†๋Š”๋ฐ ๋‚ ์”จ๊ฐ€ ํ’€๋ฆฌ๋”๋‹ˆ ์ด ๋†ˆ์˜ '
 '๊ณ„์ง‘์• ๊ฐ€ ๋ฏธ์ณค๋‚˜ ํ•˜๊ณ  ์˜์‹ฌํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ฒŒ๋‹ค๊ฐ€ ์กฐ๊ธˆ ๋’ค์—๋Š” ์ œ ์ง‘๊ป˜๋ฅผ ํ•  ๊ธˆํ•  ๊ธˆ ๋Œ์•„๋ณด๋”๋‹ˆ ํ–‰์ฃผ์น˜๋งˆ์˜ ์†์œผ๋กœ ๊ผˆ๋˜ ๋ฐ”๋ฅธ ์†์„ ๋ฝ‘์•„์„œ ์ œ ํ„ฑ '
 '๋ฐ‘์œผ๋กœ ๋ถˆ์‘ฅ ๋‚ด๋ฏธ๋Š” ๊ฒ๋‹ˆ๋‹ค. ์–ธ์ œ ๊ตฌ์› ๋Š”์ง€ ๋”์šด ๊น€์ด ํ™ฑ ๋ผ์น˜๋Š” ๊ตต์€ ๊ฐ์ž ์„ธ ๊ฐœ๊ฐ€ ์†์— ๋ฟŒ๋“ฏ์ด ์ฅ์˜€์Šต๋‹ˆ๋‹ค. "๋Š ์ง‘์—๋Š” ์ด ๊ฑฐ '
 '์—†์Šต๋‹ˆ๊นŒ? "ํ•˜๊ณ  ์ƒ์ƒ‰ ์žˆ๋Š” ํฐ ์†Œ๋ฆฌ๋ฅผ ํ•˜๊ณ ๋Š” ์ œ๊ฐ€ ์ค€ ๊ฒƒ์„ ๋‚จ์ด ์•Œ๋ฉด์€ ํฐ์ผ ๋‚  ํ…Œ๋‹ˆ ์—ฌ๊ธฐ์„œ ์–ผ๋ฅธ ๋จน์–ด ๋ฒ„๋ฆฌ๋ž๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋˜ ํ•˜๋Š” '
 '์†Œ๋ฆฌ๊ฐ€,"๋‹น์‹  ๋ด„ ๊ฐ์ž๊ฐ€ ๋ง›์žˆ์Šต๋‹ˆ๋‹ค. ""๋‚œ ๊ฐ์ž ์•ˆ ๋จน์Šต๋‹ˆ๋‹ค. ๋‹น์‹ ์ด๋‚˜ ๋จน์‹ญ์‹œ์˜ค. "์ €๋Š” ๊ณ ๊ฐœ๋„ ๋Œ๋ฆฌ์ง€ ์•Š๊ณ  ์ผํ•˜๋˜ ์†์œผ๋กœ ๊ทธ ๊ฐ์ž๋ฅผ '
 '๋„๋กœ ์–ด๊นจ ๋„ˆ๋จธ๋กœ ์‘ฅ ๋ฐ€์–ด ๋ฒ„๋ ธ์Šต๋‹ˆ๋‹ค. ๊ทธ๋žฌ๋”๋‹ˆ ๊ทธ๋ž˜๋„ ๊ฐ€๋Š” ๊ธฐ์ƒ‰์ด ์—†๊ณ , ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์Œ”๊ทผ์Œ”๊ทผํ•˜๊ณ  ์‹ฌ์ƒํ•˜์ง€ ์•Š๊ฒŒ ์ˆจ์†Œ๋ฆฌ๊ฐ€ ์ ์  '
 '๊ฑฐ์น ์–ด์ง‘๋‹ˆ๋‹ค. ์ด๊ฑฐ๋Š” ๋˜ ๋ญ์•ผ ์‹ถ์–ด์„œ ๊ทธ ๋•Œ์—์•ผ ๋น„๋กœ์†Œ ๋Œ์•„๋‹ค๋ณด๋‹ˆ ์ €๋Š” ์ฐธ์œผ๋กœ ๋†€๋ž์Šต๋‹ˆ๋‹ค. ์ €ํฌ๊ฐ€ ์ด ๋™๋„ค์— ๋“ค์–ด์˜จ ๊ฒƒ์€ ๊ทผ ์‚ผ ๋…„์งธ ๋ผ '
 '์˜ค์ง€๋งŒ ์—ฌํƒœ๊ป ๊ฐ€๋ฌด์žก์žกํ•œ ์ ์ˆ˜๋Š” ์ด์˜ ์–ผ๊ตด์ด ์ด๋ ‡๊ฒŒ๊นŒ์ง€ ํ™๋‹น๋ฌด์ฒ˜๋Ÿผ ์ƒˆ๋นจ๊ฐœ์ง„ ๋ฒ•์ด ์—†์—ˆ์Šต๋‹ˆ๋‹ค. ๊ฒŒ๋‹ค๊ฐ€ ๋ˆˆ์— ๋…์„ ์˜ฌ๋ฆฌ๊ณ  ํ•œ์ฐธ ์ €๋ฅผ ์š”๋ ‡๊ฒŒ '
 '์˜์•„๋ณด๋”๋‹ˆ ๋‚˜์ค‘์—๋Š” ๋ˆˆ๋ฌผ๊นŒ์ง€ ์–ด๋ฆฌ๋Š” ๊ฒŒ ์•„๋‹™๋””๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋ฐ”๊ตฌ๋‹ˆ๋ฅผ ๋‹ค์‹œ ์ง‘์–ด ๋“ค๋”๋‹ˆ ์ด๋ฅผ ๊ผญ ์•…๋ฌผ๊ณ ๋Š” ์—Ž์–ด์งˆ ๋“ฏ ์ž๋น ์งˆ ๋“ฏ ๋…ผ๋‘‘์œผ๋กœ '
 'ํšกํ•˜๊ฒŒ ๋‹ฌ์•„๋‚˜๋Š” ๊ฒ๋‹ˆ๋‹ค.')

4๏ธโƒฃ add_rules of your own

you can add your own rules with add_rules method. Use politely.SELF to keep MASK as-is. Use politely.NULL to remove MASK.

from politely import SELF, NULL
styler.add_rules(
        {
            "์ด๐ŸทVCP๐Ÿ”—(?P<MASK>๋‹ค๐ŸทEF)": (
             {SELF},
             {"์˜ˆ์š”๐ŸทEF"},   # ์—์š” (X) ์˜ˆ์š” (O)
             {"์ž…๋‹ˆ๋‹ค๐ŸทEF"},
            ),
            "(?P<MASK>์ด๐ŸทVCP)๐Ÿ”—๋‹ค๐ŸทEF": (
             {SELF},
             {NULL},  # ์ง€์šฐ๊ธฐ
             {NULL}   # ์ง€์šฐ๊ธฐ
            )
        })
sent = "ํ•œ๊ธ€์€ ํ•œ๊ตญ์˜ ๊ธ€์ž์ด๋‹ค."
print(styler(sent, 1))
ํ•œ๊ธ€์€ ํ•œ๊ตญ์˜ ๊ธ€์ž์˜ˆ์š”.

Here is another example of adding rules.styler.logs['guess']['out'] keeps track of all the candidates with scores.

from politely import SELF
styler.add_rules(
    {
        r"(?P<MASK>(์•„๋น |์•„๋ฒ„์ง€|์•„๋ฒ„๋‹˜)๐ŸทNNG)": (
            {f"์•„๋น ๐ŸทNNG"},
            {f"์•„๋ฒ„์ง€๐ŸทNNG", f"์•„๋ฒ„๋‹˜๐ŸทNNG"},
            {f"์•„๋ฒ„์ง€๐ŸทNNG", f"์•„๋ฒ„๋‹˜๐ŸทNNG"}
        ),
        r"(์•„๋น |์•„๋ฒ„์ง€|์•„๋ฒ„๋‹˜)๐ŸทNNG๐Ÿ”—(?P<MASK>\S+?๐ŸทJKS)": (
            {SELF},  #  no change, replace with the original
            {f"๊ป˜์„œ๐ŸทJKS"},
            {f"๊ป˜์„œ๐ŸทJKS"}
        ),
        r"(?P<MASK>แ†ซ๋‹ค๐ŸทEF)": (
            {SELF},  # no change, replace with the original
            {"์‹œ๐ŸทEP๐Ÿ”—์–ด์š”๐ŸทEF"},
            {"์‹œ๐ŸทEP๐Ÿ”—์Šต๋‹ˆ๋‹ค๐ŸทEF"},
        )
    }
)
sent = "์•„๋น ๊ฐ€ ์ •์‹ค์— ๋“ค์–ด๊ฐ„๋‹ค."
print(styler(sent, 1))
from pprint import pprint
pprint(styler.logs['guess']['out'])
์•„๋ฒ„์ง€๊ป˜์„œ ์ •์‹ค์— ๋“ค์–ด๊ฐ€์…”์š”.
[(['์•„๋ฒ„์ง€๐ŸทNNG', '๊ป˜์„œ๐ŸทJKS', '์ •์‹ค๐ŸทNNG', '์—๐ŸทJKB', '๋“ค์–ด๊ฐ€๐ŸทVV', '์‹œ๐ŸทEP', '์–ด์š”๐ŸทEF', '.๐ŸทSF'],
  0.0125),
 (['์•„๋ฒ„๋‹˜๐ŸทNNG', '๊ป˜์„œ๐ŸทJKS', '์ •์‹ค๐ŸทNNG', '์—๐ŸทJKB', '๋“ค์–ด๊ฐ€๐ŸทVV', '์‹œ๐ŸทEP', '์–ด์š”๐ŸทEF', '.๐ŸทSF'],
  0.0125)]

5๏ธโƒฃ Take contexts into account with the gpt2 scorer

heuristic scorer is fast, but falls short at taking context into account:

styler = Styler(scorer="heuristic")
print("##### lm์„ ์“ฐ์ง€ ์•Š๋Š” ๊ฒฝ์šฐ ๋งฅ๋ฝ ๊ณ ๋ ค X ######")
print(styler("๋‚ด์ผ ์ €๋ž‘ ๊ฐ™์ด ์ ์‹ฌ ๋จน์–ด์š”.", 0))
##### lm์„ ์“ฐ์ง€ ์•Š๋Š” ๊ฒฝ์šฐ ๋งฅ๋ฝ ๊ณ ๋ ค X ######
๋‚ด์ผ ๋‚˜๋ž‘ ๊ฐ™์ด ์ ์‹ฌ ๋จน์–ด.

sbg scorer (SkipBigram) is a bit slower, but does take context into account.

# Pytorch is required to use GPT2 scorer. Install the version that fits your environment.
pip3 install torch
from politely.modeling_gpt2_scorer import GPT2Scorer
styler = Styler(scorer="sbg")  # uses GPT2Scorer by default
print("##### lm์„ ์“ฐ๋Š” ๊ฒฝ์šฐ ๋งฅ๋ฝ ๊ณ ๋ ค O ######")
print(styler("๋‚ด์ผ ์ €๋ž‘ ๊ฐ™์ด ์ ์‹ฌ ๋จน์–ด์š”.", 0))
##### lm์„ ์“ฐ๋Š” ๊ฒฝ์šฐ ๋งฅ๋ฝ ๊ณ ๋ ค O ######
๋‚ด์ผ ๋‚˜๋ž‘ ๊ฐ™์ด ์ ์‹ฌ ๋จน์ž.  # ๊ถŒ์œ ๊ฐ€ ์•„๋‹Œ ์ฒญ์œ ์ด๋ฏ€๋กœ ์ด๊ฒŒ ๋งž์Œ

gpt2 scorer is the most accurate, but it is also the slowest.

# need to install optional dependency
pip3 install "politely[gpt2]"
styler = Styler(scorer="gpt2")
print("##### lm์„ ์“ฐ๋Š” ๊ฒฝ์šฐ ๋งฅ๋ฝ ๊ณ ๋ ค O ######")
print(styler("๋‚ด์ผ ์ €๋ž‘ ๊ฐ™์ด ์ ์‹ฌ ๋จน์–ด์š”.", 0))
##### lm์„ ์“ฐ๋Š” ๊ฒฝ์šฐ ๋งฅ๋ฝ ๊ณ ๋ ค O ######
๋‚ด์ผ ์ €๋ž‘ ๊ฐ™์ด ์ ์‹ฌ ๋จน์œผ๋Ÿฌ ๊ฐ€์š”.  # ๊ถŒ์œ ์ด๋ฏ€๋กœ ์ด๊ฒŒ ๋งž์Œ

Hosting the interactive demo

You can either host the interactive demo locally (You have to setup your own OPENAI_API_KEY)

export OPENAI_API_KEY = ...
# host the demo via streamlit
streamlit run main_streamlit.py
Or just visit the demo we are hosting for you
image

By whom? ๐Ÿ‘

  • funded by: Faculty of Oriental Studies at the University of Oxford
  • led & developed by: Jieun Kiaer (Associate Professor of Korean Language and Linguistics at the University of Oxford)
  • co-developed by: Research assistant Eu-Bin KIM (Msc. in Applied Linguistics at the University of Oxford, Bsc. in AI at the University of Manchester )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

politely-4.0.1.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

politely-4.0.1-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file politely-4.0.1.tar.gz.

File metadata

  • Download URL: politely-4.0.1.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.1 CPython/3.12.2 Darwin/23.1.0

File hashes

Hashes for politely-4.0.1.tar.gz
Algorithm Hash digest
SHA256 130f1341b912b61e208347736efd5f193d604f08c396e478ba4e08e56ef192b9
MD5 ee7efccbe8da6ebf0c61ec02222208a2
BLAKE2b-256 e5ec24177409ceb55ed181d6eb17df92bfb26d1609f88e5285ea5f2dffc5c3ce

See more details on using hashes here.

File details

Details for the file politely-4.0.1-py3-none-any.whl.

File metadata

  • Download URL: politely-4.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.1 CPython/3.12.2 Darwin/23.1.0

File hashes

Hashes for politely-4.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d104b6cae338e30f6e4c923ecebefe617dc3cc836c37b0d5e155c7d4ad2ffbd0
MD5 6595dcdfb066f5a34d510e1f980b541a
BLAKE2b-256 3d53814d91493d3aace62e771b694a43b158a1f34f5fedfac76fed67d41d7a75

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page