tongrams-rs : 녹에서 수많은 N- 그램 이것은 압축 공간에서 대형 언어 모델을 색인하고 쿼리하기위한 tongrams 의 녹 포트로, 데이터 구조가 다음 논문에 제시됩니다.
Giulio Ermanno Pibiri 및 Rossano Venturini, 대규모 N- 그램 데이터 세트를위한 효율적인 데이터 구조. 정보 검색 연구 개발에 관한 40 번째 ACM 회의 (SIGIR 2017) , 615-624 쪽.
Giulio Ermanno Pibiri와 Rossano Venturini는 대규모 N- 그램 데이터 세트를 효율적으로 처리합니다. 정보 시스템에 대한 ACM 트랜잭션 (TOIS) , 37.2 (2019) : 1-41.
N- 그램 언어 모델을 주파수 카운트로 저장하십시오.
주파수 계수를 얻으려면 N- 그램을 찾아보십시오.
압축 언어 모델. tongrams-rs 큰 N- 그램 언어 모델을 매우 압축 공간에 저장할 수 있습니다. 예를 들어, test_data 의 n -gram 데이터 세트 ( n = 1..5)는 그램 당 2.6 바이트로 저장됩니다.
시간과 기억 효율성. tongrams-rs Elias-Fano 코드를 통해 N- 그램으로 구성된 트리 데이터 구조를 영리하게 인코딩하는 Elias-Fano Trie를 사용하여 압축 공간에서 빠른 조회를 가능하게합니다.
순수한 녹. tongrams-rs 녹으로 만 작성되며 녹 코드에 쉽게 연결할 수 있습니다.
N -Gram Count 파일의 파일 형식은 수정 된 Google 형식 인 tongrams 에서 사용 된 것과 동일합니다.
<number_of_grams> 파일의 ngram 수를 나타냅니다.<gram> 의 토큰은 공간 (예 : the same time )에 의해 구해졌으며<gram> 및 카운트 <count> 는 수평 탭으로 구해집니다. <number_of_grams>
<gram1><TAB><count1>
<gram2><TAB><count2>
<gram3><TAB><count3>
...
예를 들어,
61516
the // parent 1
the function is 22
the function a 4
the function to 1
the function and 1
...
tools 이 라이브러리를 즐기기위한 일부 명령 줄 도구를 제공합니다. 다음에서, 예제 사용법은 tongrams 에서 복사 한 test_data 의 n -gram count 파일을 사용하여 제시됩니다.
Trie 인덱스를 만들려면 N- 그램 카운트 파일을 정렬해야합니다. 먼저, 그 결과 색인을 더 작게 만들기 위해 카운트로 정렬 된 유니 그램 카운트 파일을 준비합니다.
$ cat test_data/1-grams.sorted
8761
the 3681
is 1869
a 1778
of 1672
to 1638
and 1202
...
유니그램 파일을 어휘로 사용하면 실행 sort_grams 는 N -Gram Counts 파일을 정렬합니다.
여기서 우리는 분류되지 않은 Bigram Counts 파일을 정렬합니다
$ cat test_data/2-grams
38900
ways than 1
may come 1
frequent causes 1
way has 1
in which 14
...
bigram 파일 (gzip 형식)을 정렬하고 다음 명령으로 작성된 test_data/2-grams.sorted 작성할 수 있습니다.
$ cargo run --release -p tools --bin sort_grams -- -i test_data/2-grams.gz -v test_data/1-grams.sorted.gz -o test_data/2-grams.sorted
Loading the vocabulary: "test_data/1-grams.sorted.gz"
Loading the records: "test_data/2-grams.gz"
Sorting the records
Writing the index into "test_data/2-grams.sorted.gz"
출력 파일 형식은 -f 로 지정할 수 있으며 기본 설정은 .gz 입니다. 결과 파일이 있습니다
$ cat test_data/2-grams.sorted
38900
the // 1
the function 94
the if 3
the code 126
the compiler 117
...
실행 가능한 index (정렬 된) n -gram counts 파일 <order>-grams.sorted.gz 에서 언어 모델을 구축하고 이진 파일로 씁니다. 입력 파일 형식은 -f 로 지정할 수 있고 기본 설정은 .gz 입니다.
예를 들어, 다음 명령은 n -gram counts 파일 ( n = 1..5)에서 Directory test_data 에 배치 된 언어 모델을 빌드하여 index.bin 에 씁니다.
$ cargo run --release -p tools --bin index -- -n 5 -i test_data -o index.bin
Input files: ["test_data/1-grams.sorted.gz", "test_data/2-grams.sorted.gz", "test_data/3-grams.sorted.gz", "test_data/4-grams.sorted.gz", "test_data/5-grams.sorted.gz"]
Counstructing the index...
Elapsed time: 0.190 [sec]
252550 grams are stored.
Writing the index into "index.bin"...
Index size: 659366 bytes (0.629 MiB)
Bytes per gram: 2.611 bytes
표준 출력이 보여 지듯이 모델 파일은 그램 당 2.6 바이트 만 사용합니다.
실행 가능 lookup 다음과 같이 N- 그램을 조회하는 데모를 제공합니다.
$ cargo run --release -p tools --bin lookup -- -i index.bin
Loading the index from "index.bin"...
Performing the lookup...
> take advantage
count = 8
> only 64-bit execution
count = 1
> Elias Fano
Not found
>
Good bye!
실행 stats 각 구성 요소에 대한 메모리 사용의 고장을 보여줍니다.
$ cargo run --release -p tools --bin stats -- -i index.bin
Loading the index from "index.bin"...
{"arrays":[{"pointers":5927,"token_ids":55186},{"pointers":19745,"token_ids":92416},{"pointers":25853,"token_ids":107094},{"pointers":28135,"token_ids":111994}],"count_ranks":[{"count_ranks":5350},{"count_ranks":12106},{"count_ranks":13976},{"count_ranks":14582},{"count_ranks":14802}],"counts":[{"count":296},{"count":136},{"count":72},{"count":56},{"count":56}],"vocab":{"data":151560}}
디렉토리 bench 에서는 다음 명령으로 test_data 에서 n- 그램 데이터를 사용하여 조회 시간을 측정 할 수 있습니다.
$ RUSTFLAGS="-C target-cpu=native" cargo bench
count_lookup/tongrams/EliasFanoTrieCountLm
time: [3.1818 ms 3.1867 ms 3.1936 ms]
보고 된 시간은 5K 랜덤 그램을 찾는 총 경과 시간입니다. 위의 결과는 실제로 내 노트북 PC (Intel i7, 16GB RAM)에서 얻어졌으며, 즉 EliasFanoTrieCountLm 평균적으로 0.64 마이크로 SEC에서 그램을 찾을 수 있습니다.
sucds::EliasFano 더 빨리 만드십시오 이 라이브러리는 MIT에서 제공되는 무료 소프트웨어입니다.