https://github.com/surzia/go-n-gram
N-gram model implemented by golang
https://github.com/surzia/go-n-gram
golang n-grams
Last synced: 7 months ago
JSON representation
N-gram model implemented by golang
- Host: GitHub
- URL: https://github.com/surzia/go-n-gram
- Owner: surzia
- Created: 2022-01-23T03:10:01.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-01-23T05:32:12.000Z (over 3 years ago)
- Last Synced: 2025-01-28T14:52:35.214Z (9 months ago)
- Topics: golang, n-grams
- Language: Go
- Homepage: https://juejin.cn/post/7056272302110933022
- Size: 348 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# README
This is an N-gram model implemented by go.
## N-gram
A language model is a probability distribution over sequences of words `W`, namely:
According to the chain rule,

We can use [Maximum Likelihood Estimation](https://leimao.github.io/blog/Maximum-Likelihood-Estimation-Ngram/)

## Usage
You can run it directly, as:
```shell
go run . -word "中国"
```
or run it after compilation:
```shell
go build .
./go-n-gram -word "中国"
```
the output is:
```
The next word is 人, probability is 0.071429
The next word is 扶, probability is 0.055556
The next word is 的, probability is 0.039683
The next word is 社, probability is 0.039683
The next word is ,, probability is 0.039683
......
```