pub struct JevTokenizer { /* private fields */ }Expand description
Jev システム用高速トークナイザー。
Implementations§
Source§impl JevTokenizer
impl JevTokenizer
Sourcepub fn encode_batch_questions(
&self,
state: &str,
questions: &IndexMap<String, Question>,
) -> Result<BatchTokenizedQuestions>
pub fn encode_batch_questions( &self, state: &str, questions: &IndexMap<String, Question>, ) -> Result<BatchTokenizedQuestions>
Sourcepub fn encode_batch_questions_with_max_len(
&self,
state: &str,
questions: &IndexMap<String, Question>,
max_length: usize,
) -> Result<BatchTokenizedQuestions>
pub fn encode_batch_questions_with_max_len( &self, state: &str, questions: &IndexMap<String, Question>, max_length: usize, ) -> Result<BatchTokenizedQuestions>
系列長制約を明示指定して、共通 State と複数質問群を一括エンコードする。
§処理フロー
stateをencode_stateにより 1 度だけトークナイズし、トークン ID 列を共有する。- 各質問に対して独立した State 優先トランケーションを適用し、個別トークナイズを実行する。
- バッチ内の最大系列長 $L_{\max}$ および最大候補数 $K_{\max}$ を算出する。
- パディングトークンおよび安全なダミー候補インデックス (0) を用いて平坦化バッファを構築する。
§引数
state: 共通文脈テキスト。questions: 質問識別子と質問定義のマップ。max_length: 許容最大入力系列長。
§エラー
- 質問群が空の場合は
InvalidQuestion。 - テンソル形状が不正な場合は
ModelContractViolation。
Sourcepub fn encode_batch_with_pretokenized_state(
&self,
state_ids: &[u32],
questions: &IndexMap<String, Question>,
max_length: usize,
) -> Result<BatchTokenizedQuestions>
pub fn encode_batch_with_pretokenized_state( &self, state_ids: &[u32], questions: &IndexMap<String, Question>, max_length: usize, ) -> Result<BatchTokenizedQuestions>
事前エンコード済み State トークン列を用いて複数質問群を一括バッチエンコードする。
サーバー層でのマイクロバッチ分割(チャンキング)時に、同一 State の再トークナイズを完全に防ぐ。
§引数
state_ids: 事前トークナイズ済み State トークン ID 列。questions: 質問識別子と質問定義のマップ。max_length: 許容最大入力系列長。
Source§impl JevTokenizer
impl JevTokenizer
Sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Self>
pub fn from_file(path: impl AsRef<Path>) -> Result<Self>
トークナイザー定義ファイル (tokenizer.json) からインスタンスを初期化する。
最大系列長にはデフォルトの MAX_SEQUENCE_LENGTH (8192) が適用される。
§エラー
ファイルのロード失敗、[OP] トークン不在、または [OP] トークン分割テストに失敗した場合にエラーを返す。
Sourcepub fn from_file_with_max_length(
path: impl AsRef<Path>,
max_sequence_length: usize,
) -> Result<Self>
pub fn from_file_with_max_length( path: impl AsRef<Path>, max_sequence_length: usize, ) -> Result<Self>
最大系列長を指定してトークナイザー定義ファイルからインスタンスを初期化する。
§エラー
ファイルのロード失敗、[OP] トークン不在、または [OP] トークン分割テストに失敗した場合にエラーを返す。
Sourcepub fn from_tokenizer_with_max_length(
inner: Tokenizer,
max_sequence_length: usize,
) -> Result<Self>
pub fn from_tokenizer_with_max_length( inner: Tokenizer, max_sequence_length: usize, ) -> Result<Self>
既存の tokenizers::Tokenizer インスタンスから初期化する。
Sourcepub fn op_token_id(&self) -> u32
pub fn op_token_id(&self) -> u32
[OP] マーカーのトークン ID を取得する。
Sourcepub fn pad_token_id(&self) -> Option<u32>
pub fn pad_token_id(&self) -> Option<u32>
パディングトークン ID を取得する。
Sourcepub fn leading_special_tokens(&self) -> &[u32]
pub fn leading_special_tokens(&self) -> &[u32]
先頭特殊トークン ID 列を取得する。
Sourcepub fn trailing_special_tokens(&self) -> &[u32]
pub fn trailing_special_tokens(&self) -> &[u32]
末尾特殊トークン ID 列を取得する。
Sourcepub fn state_prefix_tokens(&self) -> &[u32]
pub fn state_prefix_tokens(&self) -> &[u32]
固定プレフィックス "State: " のキャッシュ済みトークン ID 列を取得する。
Sourcepub fn max_sequence_length(&self) -> usize
pub fn max_sequence_length(&self) -> usize
設定されている最大系列長を取得する。
Sourcepub fn encode_state(&self, state: &str) -> Result<Vec<u32>>
pub fn encode_state(&self, state: &str) -> Result<Vec<u32>>
State 文字列を事前にトークナイズする (プレフィックス共有用)。
Sourcepub fn encode_question(
&self,
state: &str,
question: &Question,
) -> Result<TokenizedQuestion>
pub fn encode_question( &self, state: &str, question: &Question, ) -> Result<TokenizedQuestion>
単一の State と Question から ONNX 入力用バッファを生成する。
Sourcepub fn encode_question_with_max_len(
&self,
state: &str,
question: &Question,
max_length: usize,
) -> Result<TokenizedQuestion>
pub fn encode_question_with_max_len( &self, state: &str, question: &Question, max_length: usize, ) -> Result<TokenizedQuestion>
系列長制約を明示指定して、単一の State と Question をエンコードする。
Sourcepub fn encode_with_pretokenized_state(
&self,
state_ids: &[u32],
question: &Question,
max_length: usize,
) -> Result<TokenizedQuestion>
pub fn encode_with_pretokenized_state( &self, state_ids: &[u32], question: &Question, max_length: usize, ) -> Result<TokenizedQuestion>
事前エンコード済み State トークン列を用いてエンコードする (State 優先トランケーション適用)。
§State 優先トランケーションの不変条件
文末の Criteria (すべての [OP] マーカー群) および Instructions を絶対に保護し、
系列長が上限を超える場合は State のみ末尾からスライスして切り詰める。
§エラー
- 固定部 (特殊トークン + Prefix + Instructions + Criteria) が
max_length以上の場合はPromptExceedsMaxLength。 - 検出された
[OP]マーカー数と候補数が不一致の場合はOptionMarkerCountMismatch。
Sourcepub fn encode_query(&self, question: &Question) -> Result<TokenizedQuestion>
pub fn encode_query(&self, question: &Question) -> Result<TokenizedQuestion>
単一の質問定義から QueryEvaluator 入力用トークン列および [OP] マーカー位置を生成する。
§戻り値
TokenizedQuestion: Query 部分のinput_ids、attention_mask、op_indices、option_keys。
Sourcepub fn encode_query_with_max_len(
&self,
question: &Question,
max_length: usize,
) -> Result<TokenizedQuestion>
pub fn encode_query_with_max_len( &self, question: &Question, max_length: usize, ) -> Result<TokenizedQuestion>
系列長制約を指定して、単一の質問定義から QueryEvaluator 入力用トークン列を生成する。
Trait Implementations§
Source§impl Clone for JevTokenizer
impl Clone for JevTokenizer
Source§fn clone(&self) -> JevTokenizer
fn clone(&self) -> JevTokenizer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for JevTokenizer
impl RefUnwindSafe for JevTokenizer
impl Send for JevTokenizer
impl Sync for JevTokenizer
impl Unpin for JevTokenizer
impl UnsafeUnpin for JevTokenizer
impl UnwindSafe for JevTokenizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more