-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
50 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
mod disk_utils; | ||
pub mod index; | ||
mod text_utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use std::{fs::create_dir_all, path::Path}; | ||
|
||
use tokenizers::Tokenizer; | ||
|
||
pub fn load_tokenizer(filename: &str, force_download: bool) -> Tokenizer { | ||
let path = Path::new(filename); | ||
|
||
if !path.exists() || force_download { | ||
path.parent().map(create_dir_all); | ||
|
||
let identifier = path.file_name().unwrap().to_str().unwrap(); | ||
|
||
Tokenizer::from_pretrained(identifier, None) | ||
.expect("error while retrieving tokenizer from the web") | ||
.save(filename, false) | ||
.expect("error while saving tokenizer to file"); | ||
} | ||
|
||
Tokenizer::from_file(filename).expect("error while loading tokenizer from file") | ||
} | ||
|
||
pub fn tokenize(tokenizer: &Tokenizer, text: &str) -> Vec<String> { | ||
tokenizer | ||
.encode(text, false) | ||
.expect("error while tokenizing text") | ||
.get_tokens() | ||
.to_vec() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
pub mod disk; | ||
pub mod indexer; | ||
pub mod text; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.