Skip to main content

JevTokenizer

Struct JevTokenizer 

Source
pub struct JevTokenizer { /* private fields */ }
Expand description

Jev システム用高速トークナイザー。

Implementations§

Source§

impl JevTokenizer

Source

pub fn encode_batch_questions( &self, state: &str, questions: &IndexMap<String, Question>, ) -> Result<BatchTokenizedQuestions>

共通 State と複数質問群からプレフィックス共有バッチトークナイズ結果を生成する。

最大系列長にはインスタンスに設定されている max_sequence_length が適用される。

§引数
  • state: 共通文脈テキスト。
  • questions: 質問識別子と質問定義のマップ。
§戻り値

パディングおよび平坦化済みの BatchTokenizedQuestions。

§エラー
  • 質問群が空の場合は InvalidQuestion。
  • 系列長超過またはマーカー不整合の場合は RuntimeError。
Source

pub fn encode_batch_questions_with_max_len( &self, state: &str, questions: &IndexMap<String, Question>, max_length: usize, ) -> Result<BatchTokenizedQuestions>

系列長制約を明示指定して、共通 State と複数質問群を一括エンコードする。

§処理フロー
  1. state を encode_state により 1 度だけトークナイズし、トークン ID 列を共有する。
  2. 各質問に対して独立した State 優先トランケーションを適用し、個別トークナイズを実行する。
  3. バッチ内の最大系列長 $L_{\max}$ および最大候補数 $K_{\max}$ を算出する。
  4. パディングトークンおよび安全なダミー候補インデックス (0) を用いて平坦化バッファを構築する。
§引数
  • state: 共通文脈テキスト。
  • questions: 質問識別子と質問定義のマップ。
  • max_length: 許容最大入力系列長。
§エラー
  • 質問群が空の場合は InvalidQuestion。
  • テンソル形状が不正な場合は ModelContractViolation。
Source

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

Source

pub fn from_file(path: impl AsRef<Path>) -> Result<Self>

トークナイザー定義ファイル (tokenizer.json) からインスタンスを初期化する。

最大系列長にはデフォルトの MAX_SEQUENCE_LENGTH (8192) が適用される。

§エラー

ファイルのロード失敗、[OP] トークン不在、または [OP] トークン分割テストに失敗した場合にエラーを返す。

Source

pub fn from_file_with_max_length( path: impl AsRef<Path>, max_sequence_length: usize, ) -> Result<Self>

最大系列長を指定してトークナイザー定義ファイルからインスタンスを初期化する。

§エラー

ファイルのロード失敗、[OP] トークン不在、または [OP] トークン分割テストに失敗した場合にエラーを返す。

Source

pub fn from_tokenizer_with_max_length( inner: Tokenizer, max_sequence_length: usize, ) -> Result<Self>

既存の tokenizers::Tokenizer インスタンスから初期化する。

Source

pub fn op_token_id(&self) -> u32

[OP] マーカーのトークン ID を取得する。

Source

pub fn pad_token_id(&self) -> Option<u32>

パディングトークン ID を取得する。

Source

pub fn leading_special_tokens(&self) -> &[u32]

先頭特殊トークン ID 列を取得する。

Source

pub fn trailing_special_tokens(&self) -> &[u32]

末尾特殊トークン ID 列を取得する。

Source

pub fn state_prefix_tokens(&self) -> &[u32]

固定プレフィックス "State: " のキャッシュ済みトークン ID 列を取得する。

Source

pub fn max_sequence_length(&self) -> usize

設定されている最大系列長を取得する。

Source

pub fn inner(&self) -> &Tokenizer

内部の tokenizers::Tokenizer への参照を取得する。

Source

pub fn encode_state(&self, state: &str) -> Result<Vec<u32>>

State 文字列を事前にトークナイズする (プレフィックス共有用)。

Source

pub fn encode_question( &self, state: &str, question: &Question, ) -> Result<TokenizedQuestion>

単一の State と Question から ONNX 入力用バッファを生成する。

Source

pub fn encode_question_with_max_len( &self, state: &str, question: &Question, max_length: usize, ) -> Result<TokenizedQuestion>

系列長制約を明示指定して、単一の State と Question をエンコードする。

Source

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。
Source

pub fn encode_query(&self, question: &Question) -> Result<TokenizedQuestion>

単一の質問定義から QueryEvaluator 入力用トークン列および [OP] マーカー位置を生成する。

§戻り値
  • TokenizedQuestion: Query 部分の input_ids、attention_mask、op_indices、option_keys。
Source

pub fn encode_query_with_max_len( &self, question: &Question, max_length: usize, ) -> Result<TokenizedQuestion>

系列長制約を指定して、単一の質問定義から QueryEvaluator 入力用トークン列を生成する。

Source

pub fn encode_state_tensor(&self, state: &str) -> Result<(Vec<i64>, Vec<i64>)>

State 文字列を StateEncoder 入力用トークン列 (input_ids, attention_mask) としてエンコードする。

Trait Implementations§

Source§

impl Clone for JevTokenizer

Source§

fn clone(&self) -> JevTokenizer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for JevTokenizer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more