• 文件 >
  • torchtext.functional
捷徑

torchtext.functional

to_tensor

torchtext.functional.to_tensor(input: Any, padding_value: Optional[int] = None, dtype: dtype = torch.int64) Tensor[原始碼]

將輸入轉換為 torch 張量

參數
  • padding_value (Optional[int]) – 填充值,使批次中每個輸入的長度等於批次中最長序列的長度。

  • dtype (torch.dtype) – 輸出張量的 torch.dtype

  • input (Union[List[int], List[List[int]]]) – 詞彙 ID 的序列或批次

返回類型

張量

使用 to_tensor 的教學
SST-2 Binary text classification with XLM-RoBERTa model

使用 XLM-RoBERTa 模型進行 SST-2 二元文字分類

使用 XLM-RoBERTa 模型進行 SST-2 二元文字分類

truncate

torchtext.functional.truncate(input: Any, max_seq_len: int) Any[原始碼]

截斷輸入序列或批次

參數
  • input (Union[List[Union[str, int]], List[List[Union[str, int]]]]) – 要截斷的輸入序列或批次

  • max_seq_len (int) – 超過此長度後輸入將被捨棄

返回

截斷後的序列

返回類型

Union[List[Union[str, int]], List[List[Union[str, int]]]]

add_token

torchtext.functional.add_token(input: Any, token_id: Any, begin: bool = True) Any[原始碼]

在序列的開頭或結尾新增詞彙

參數
  • input (Union[List[Union[str, int]], List[List[Union[str, int]]]]) – 輸入序列或批次

  • token_id (Union[str, int]) – 要新增的詞彙

  • begin (bool, optional) – 是否在序列的開頭或結尾插入詞彙,預設為 True

返回

在輸入的開頭或結尾新增了 token_id 的序列或批次

返回類型

Union[List[Union[str, int]], List[List[Union[str, int]]]]

str_to_int

torchtext.functional.str_to_int(input: Any) Any[原始碼]

將字串詞彙轉換為整數(單一序列或批次)。

參數

input (Union[List[str], List[List[str]]]) – 輸入序列或批次

返回

轉換為整數的字串詞彙序列或批次

返回類型

Union[List[int], List[List[int]]]

文件

取得 PyTorch 的完整開發人員文件

檢視文件

教學

取得針對初學者和進階開發人員的深入教學

檢視教學

資源

尋找開發資源並獲得問題解答

檢視資源