Skip to content

Commit e76ef3b

Browse files
committed
Shuffle order of pub interfaces
1 parent a6bb159 commit e76ef3b

File tree

3 files changed

+40
-40
lines changed

3 files changed

+40
-40
lines changed

src/index.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -159,31 +159,11 @@ impl Index {
159159
})
160160
}
161161

162-
/// Lists allowed tokens for a give state ID or `None` if it is not found in `Index`.
163-
pub fn allowed_tokens(&self, state: &StateId) -> Option<Vec<TokenId>> {
164-
self.transitions
165-
.get(state)
166-
.map(|res| res.keys().cloned().collect())
167-
}
168-
169-
/// Returns transition state for a given state and token id or `None` otherwise.
170-
pub fn next_state(&self, state: &StateId, token_id: &TokenId) -> Option<StateId> {
171-
if token_id == &self.eos_token_id {
172-
return None;
173-
}
174-
Some(*self.transitions.get(state)?.get(token_id)?)
175-
}
176-
177162
/// Returns the ID of the initial state in the automaton.
178163
pub fn initial_state(&self) -> StateId {
179164
self.initial_state
180165
}
181166

182-
/// Checks if state is in final states set or not.
183-
pub fn is_final_state(&self, state: &StateId) -> bool {
184-
self.final_states.contains(state)
185-
}
186-
187167
/// Returns set of final states.
188168
pub fn final_states(&self) -> &HashSet<StateId> {
189169
&self.final_states
@@ -193,6 +173,26 @@ impl Index {
193173
pub fn transitions(&self) -> &HashMap<StateId, HashMap<TokenId, StateId>> {
194174
&self.transitions
195175
}
176+
177+
/// Checks if state is in final states set or not.
178+
pub fn is_final_state(&self, state: &StateId) -> bool {
179+
self.final_states.contains(state)
180+
}
181+
182+
/// Lists allowed tokens for a give state ID or `None` if it is not found in `Index`.
183+
pub fn allowed_tokens(&self, state: &StateId) -> Option<Vec<TokenId>> {
184+
self.transitions
185+
.get(state)
186+
.map(|res| res.keys().cloned().collect())
187+
}
188+
189+
/// Returns transition state for a given state and token id or `None` otherwise.
190+
pub fn next_state(&self, state: &StateId, token_id: &TokenId) -> Option<StateId> {
191+
if token_id == &self.eos_token_id {
192+
return None;
193+
}
194+
Some(*self.transitions.get(state)?.get(token_id)?)
195+
}
196196
}
197197

198198
impl std::fmt::Display for Index {

src/python_bindings/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,6 @@ impl PyVocabulary {
277277
)))
278278
}
279279

280-
fn get_eos_token_id(&self) -> TokenId {
281-
self.0.eos_token_id()
282-
}
283-
284280
fn get(&self, py: Python<'_>, token: Py<PyAny>) -> PyResult<Option<Vec<TokenId>>> {
285281
if let Ok(t) = token.extract::<String>(py) {
286282
return Ok(self.0.token_ids(t.into_bytes()).cloned());
@@ -294,6 +290,10 @@ impl PyVocabulary {
294290
)))
295291
}
296292

293+
fn get_eos_token_id(&self) -> TokenId {
294+
self.0.eos_token_id()
295+
}
296+
297297
fn __repr__(&self) -> String {
298298
format!("{:#?}", self.0)
299299
}

src/vocabulary/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,6 @@ impl Vocabulary {
6666
}
6767
}
6868

69-
/// Inserts a token to the vocabulary with the specified identifier.
70-
pub fn try_insert(&mut self, token: impl Into<Token>, id: TokenId) -> Result<(), Error> {
71-
if id == self.eos_token_id {
72-
return Err(Error::EOSTokenDisallowed);
73-
}
74-
let token = token.into();
75-
self.tokens.entry(token).or_default().push(id);
76-
Ok(())
77-
}
78-
79-
/// Removes given token from the vocabulary.
80-
pub fn remove(&mut self, token: impl Into<Token>) {
81-
let token = token.into();
82-
self.tokens.remove(&token);
83-
}
84-
8569
/// Creates the vocabulary of pre-trained model from Hugging Face Hub.
8670
pub fn from_pretrained(
8771
model: &str,
@@ -148,6 +132,22 @@ impl Vocabulary {
148132
self.eos_token_id
149133
}
150134

135+
/// Inserts a token to the vocabulary with the specified identifier.
136+
pub fn try_insert(&mut self, token: impl Into<Token>, id: TokenId) -> Result<(), Error> {
137+
if id == self.eos_token_id {
138+
return Err(Error::EOSTokenDisallowed);
139+
}
140+
let token = token.into();
141+
self.tokens.entry(token).or_default().push(id);
142+
Ok(())
143+
}
144+
145+
/// Removes given token from the vocabulary.
146+
pub fn remove(&mut self, token: impl Into<Token>) {
147+
let token = token.into();
148+
self.tokens.remove(&token);
149+
}
150+
151151
/// Filters out `Prepend` kind of tokenizer's normalizers.
152152
fn filter_prepend_normalizers(tokenizer: &mut Tokenizer) {
153153
// Main concern is prepend normalizers, for example https://github.com/google/sentencepiece

0 commit comments

Comments
 (0)