Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

# kor2vec [![CircleCI](https://circleci.com/gh/kor2vec/kor2vec.svg?style=svg)](https://circleci.com/gh/kor2vec/kor2vec)

OOV없이 빠르고 정확한 Char-CNN 기반 한국어 Embedding

## Installation
```shell
pip install kor2vec
```
> Requirements : `tqdm`, `numpy` and support `torch >= 0.4.0`

## Introduction

한국어는 교착어라는 특성을 갖고 있습니다. 때문에 어간+어미(용언), 명사+조사 등등 다양한 형태의 수만가지의
단어 조합들을 만들어 낼 수 있는데요. 한국어를 사용하는 입장에서는 매우 편리한 특성이지만
한국어를 Embedding 해야하는 NLP 개발자들에게는 언제나 가장 큰 문제점으로 다가왔습니다.

때문에 `konlpy`나 `sentence piece`를 사용해서 한국어를 적절한 token 단위로 나눈뒤에
`Word2vec` 또는 자제적인 Embedding을 학습하여 교착어의 문제를 해결하였습니다.

하지만 이 방법에는 세가지 큰 문제점이 존재합니다.

1. 모든 inference, training 과정에 tokenizer가 붙어야 함으로 병목현상이 발생한다
2. tokenization 과정에서 의미를 잃어버리는 경우가 많다 (잘못된 tokenization)
3. 모든 단어와 문장을 cover하는 것은 불가능하다 (필연 OOV문제가 발생함)


## Solution

이러한 문제점을 해결하기 위해서 CNN을 기반으로 한 char-word 임베딩을 한국어에 적용하여
`kor2vec`을 만들게 되었습니다.

- Embedding 학습 방법 : Skip-gram based embedding training
- Char-word Encoder 모델 구조 : [Yoon Kim's Character-Aware Neural Language Modeling](https://arxiv.org/abs/1508.06615)

## Quick Start

```shell
kor2vec train -c corpus/path -o output/model.kor2vec
```

### inference
```python

from kor2vec import Kor2Vec
kor2vec = Kor2Vec.load("../model/path")

kor2vec.embedding("안녕 아이오아이야 나는 클로바에서 왔어")
>>> torch.tensor(5, 128) # embedding vector

kor2vec.embedding("나는 도라에몽이라고 해 반가워", numpy=True)
>>> numpy.array(4, 128) # numpy embedding vector

input = kor2vec.to_seqs(["안녕 나는 뽀로로라고 해", "만나서 반가워 뽀로로"], seq_len=4)
kor2vec.forward(input)
>> torch.tensor([2, 4, 128])
```

### training

```python
from kor2vec import Kor2vec

kor2vec = Kor2Vec(embed_size=128)

kor2vec.train("../path/corpus", batch_size=128) # takes some time

kor2vec.save("../mode/path") # saving embedding
```

### with pytorch

```python

import torch.nn as nn
from kor2vec import Kor2vec

kor2vec = Kor2Vec.load("../model/path")
# or kor2vec = SejongVector()

lstm = nn.LSTM(128, 64, batch_first=True)
dense = nn.Linear(64, 1)

# Make tensor input
sentences = ["이 영화는 정말 대박이에요", "우와 진짜 재미있었어요"]

x = kor2vec.to_seqs(sentences, seq_len=10)
# >>> tensor(batch_size, seq_len, char_seq_len)

x = kor2vec(x) # tensor(batch_size, seq_len, 128)
_, (x, xc) = lstm(x) # tensor(batch_size, 64)
x = dense(x) # tensor(batch_size, 1)

```


Copyright 2018 Kor2vec Contributors and NAVER Corporation

Metadata

Release files for kor2vec 0.0.1a0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kor2vec 0.0.1a0
File Size Uploaded
kor2vec-0.0.1a0.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kor2vec 0.0.1a0
File Interpreter ABI Platform
kor2vec-0.0.1a0-py3-none-any.whl Python 3 none any Details

Total release size: 35.6 kB

Release files / kor2vec-0.0.1a0.tar.gz

Download URL kor2vec-0.0.1a0.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0af498d520fa03c36948394973a6bd59042e01dd8ff232b2e42042780a3c74b1
BLAKE2b-256 checksum
How to use checksums
52f73de1a7bc8d4d29c7456bf22912059ecdf201008e1fa93abb8a49f63dbe41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.1

Release files / kor2vec-0.0.1a0-py3-none-any.whl

Download URL kor2vec-0.0.1a0-py3-none-any.whl
Size 22.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e76f92b8d93454dcf70c5d73797ef7ea71c5e42836583a7a8da4f71a1d132a5d
BLAKE2b-256 checksum
How to use checksums
6877a42939a91df0f148b9be405462e7c582599ce30deb5e613eca29b0c22d7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.1

Release history Release notifications | RSS feed

This release

0.0.1a0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page