-
Notifications
You must be signed in to change notification settings - Fork 2
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
5 changed files
with
51 additions
and
15 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
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,39 @@ | ||
use std::fs::File; | ||
use std::io::{Write, Read, BufReader, BufWriter}; | ||
|
||
/// | ||
/// Writes a vector of tokens to a file in the `.gtok` format. | ||
/// # Arguments | ||
/// - filename: the file to save the tokens to | ||
/// - tokens: tokens to save | ||
/// | ||
pub fn write_tokens_to_gtok(filename: &str, tokens: &[u32]) -> std::io::Result<()> { | ||
let file = File::create(filename)?; | ||
let mut writer = BufWriter::new(file); | ||
|
||
for &token in tokens { | ||
writer.write_all(&token.to_le_bytes())?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
/// | ||
/// Read in a vector of tokens from a file in the `.gtok` format. | ||
/// # Arguments | ||
/// - filename: filename to read the tokens from | ||
/// | ||
/// # Returns | ||
/// - vector of tokens in u32 format | ||
pub fn read_tokens_from_gtok(filename: &str) -> std::io::Result<Vec<u32>> { | ||
let file = File::open(filename)?; | ||
let mut reader = BufReader::new(file); | ||
let mut tokens = Vec::new(); | ||
let mut buffer = [0; 4]; | ||
|
||
while let Ok(()) = reader.read_exact(&mut buffer) { | ||
tokens.push(u32::from_le_bytes(buffer)); | ||
} | ||
|
||
Ok(tokens) | ||
} |
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 |
---|---|---|
|
@@ -9,4 +9,5 @@ pub mod common; | |
pub mod tokenizers; | ||
pub mod uniwig; | ||
pub mod vocab; | ||
pub mod tools; | ||
pub mod tools; | ||
pub mod io; |
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