pytext.torchscript package

Submodules

pytext.torchscript.batchutils module

pytext.torchscript.batchutils.clip_list(input: Optional[List[str]], max_batch: int) → Optional[List[str]][source]
pytext.torchscript.batchutils.clip_listlist(input: Optional[List[List[str]]], max_batch: int) → Optional[List[List[str]]][source]
pytext.torchscript.batchutils.clip_listlist_float(input: Optional[List[List[float]]], max_batch: int) → Optional[List[List[float]]][source]
pytext.torchscript.batchutils.destructure_any_list(client_batch: List[int], result_any_list: List[Any])[source]
pytext.torchscript.batchutils.destructure_dict_list(client_batch: List[int], result_input_list: List[Dict[str, float]]) → List[List[Dict[str, float]]][source]
pytext.torchscript.batchutils.destructure_dictlist_list(client_batch: List[int], result_input_list: List[List[Dict[str, float]]]) → List[List[List[Dict[str, float]]]][source]
pytext.torchscript.batchutils.destructure_tensor(client_batch: List[int], result_tensor: torch.Tensor) → List[torch.Tensor][source]
pytext.torchscript.batchutils.destructure_tensor_list(client_batch: List[int], result_tensor_list: List[torch.Tensor]) → List[List[torch.Tensor]][source]
pytext.torchscript.batchutils.input_size(texts: Optional[List[str]] = None, multi_texts: Optional[List[List[str]]] = None, tokens: Optional[List[List[str]]] = None) → int[source]
pytext.torchscript.batchutils.limit_list(input: Optional[List[str]], max_batch: int) → Optional[List[str]][source]
pytext.torchscript.batchutils.limit_listlist(input: Optional[List[List[str]]], max_batch: int) → Optional[List[List[str]]][source]
pytext.torchscript.batchutils.limit_listlist_float(input: Optional[List[List[float]]], max_batch: int) → Optional[List[List[float]]][source]
pytext.torchscript.batchutils.listify(t: torch.Tensor) → List[torch.Tensor][source]
pytext.torchscript.batchutils.make_batch_texts(tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, mega_batch: List[Tuple[List[str], int]], goals: Dict[str, str]) → List[List[Tuple[List[str], int]]][source]
pytext.torchscript.batchutils.make_batch_texts_dense(tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, mega_batch: List[Tuple[List[str], List[List[float]], int]], goals: Dict[str, str]) → List[List[Tuple[List[str], List[List[float]], int]]][source]
pytext.torchscript.batchutils.make_prediction_texts(batch: List[Tuple[List[str]]]) → List[str][source]
pytext.torchscript.batchutils.make_prediction_texts_dense(batch: List[Tuple[List[str], List[List[float]]]]) → Tuple[List[str], List[List[float]]][source]
pytext.torchscript.batchutils.make_prediction_tokens(batch: List[Tuple[List[List[str]]]]) → List[List[str]][source]
pytext.torchscript.batchutils.max_tokens(per_sentence_tokens: List[List[Tuple[str, int, int]]]) → int[source]

receive the tokenize output for a batch per_sentence_tokens, return the max token length of any sentence

pytext.torchscript.batchutils.nonify_listlist_float(input: List[List[float]]) → Optional[List[List[float]]][source]
pytext.torchscript.batchutils.validate_batch_element(e: Tuple[Optional[List[str]], Optional[List[List[str]]], Optional[List[List[str]]], Optional[List[str]], Optional[List[List[float]]]])[source]
pytext.torchscript.batchutils.validate_dense_feat(batch_element_dense_feat: Optional[List[List[float]]], length: int, uses_dense_feat: bool) → List[List[float]][source]
pytext.torchscript.batchutils.validate_make_prediction_batch_element(be: Tuple[Optional[List[str]], Optional[List[List[str]]], Optional[List[List[str]]], Optional[List[str]], Optional[List[List[float]]]])[source]
pytext.torchscript.batchutils.zip_batch_any_list_list(zip_batch_list: List[int], result_list_1: List[List[Any]], result_list_2: List[List[Any]]) → List[List[Any]][source]
pytext.torchscript.batchutils.zip_batch_tensor_list(zip_batch_list: List[int], result_list_1: List[torch.Tensor], result_list_2: List[torch.Tensor]) → List[torch.Tensor][source]

pytext.torchscript.module module

class pytext.torchscript.module.PyTextEmbeddingModule(model: torch.jit._script.ScriptModule, tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer)[source]

Bases: torch.jit._script.ScriptModule

class pytext.torchscript.module.PyTextEmbeddingModuleIndex(model: torch.jit._script.ScriptModule, tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, index: int = 0)[source]

Bases: pytext.torchscript.module.PyTextEmbeddingModule

class pytext.torchscript.module.PyTextEmbeddingModuleWithDense(model: torch.jit._script.ScriptModule, tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, normalizer: pytext.torchscript.tensorizer.normalizer.VectorNormalizer, concat_dense: bool = False)[source]

Bases: pytext.torchscript.module.PyTextEmbeddingModule

class pytext.torchscript.module.PyTextEmbeddingModuleWithDenseIndex(model: torch.jit._script.ScriptModule, tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, normalizer: pytext.torchscript.tensorizer.normalizer.VectorNormalizer, index: int = 0, concat_dense: bool = True)[source]

Bases: pytext.torchscript.module.PyTextEmbeddingModuleWithDense

class pytext.torchscript.module.PyTextLayerModule(model: torch.jit._script.ScriptModule, output_layer: torch.jit._script.ScriptModule, tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer)[source]

Bases: pytext.torchscript.module.PyTextEmbeddingModule

class pytext.torchscript.module.PyTextLayerModuleWithDense(model: torch.jit._script.ScriptModule, output_layer: torch.jit._script.ScriptModule, tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, normalizer: pytext.torchscript.tensorizer.normalizer.VectorNormalizer)[source]

Bases: pytext.torchscript.module.PyTextEmbeddingModuleWithDense

class pytext.torchscript.module.PyTextTwoTowerEmbeddingModule(model: torch.jit._script.ScriptModule, right_tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, left_tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer)[source]

Bases: torch.jit._script.ScriptModule

class pytext.torchscript.module.PyTextTwoTowerEmbeddingModuleWithDense(model: torch.jit._script.ScriptModule, right_tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, left_tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, right_normalizer: pytext.torchscript.tensorizer.normalizer.VectorNormalizer, left_normalizer: pytext.torchscript.tensorizer.normalizer.VectorNormalizer)[source]

Bases: pytext.torchscript.module.PyTextTwoTowerEmbeddingModule

class pytext.torchscript.module.PyTextTwoTowerLayerModule(model: torch.jit._script.ScriptModule, output_layer: torch.jit._script.ScriptModule, right_tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, left_tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer)[source]

Bases: pytext.torchscript.module.PyTextTwoTowerEmbeddingModule

class pytext.torchscript.module.PyTextTwoTowerLayerModuleWithDense(model: torch.jit._script.ScriptModule, output_layer: torch.jit._script.ScriptModule, right_tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, left_tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, right_normalizer: pytext.torchscript.tensorizer.normalizer.VectorNormalizer, left_normalizer: pytext.torchscript.tensorizer.normalizer.VectorNormalizer)[source]

Bases: pytext.torchscript.module.PyTextTwoTowerLayerModule

class pytext.torchscript.module.PyTextVariableSizeEmbeddingModule(model: torch.jit._script.ScriptModule, tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer)[source]

Bases: pytext.torchscript.module.PyTextEmbeddingModule

Assumes model returns a tuple of representations and sequence lengths, then slices each example’s representation according to length. Returns a list of tensors. The slicing is easier to do outside a traced model.

class pytext.torchscript.module.ScriptPyTextEmbeddingModule(model: torch.jit._script.ScriptModule, tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer)[source]

Bases: torch.jit._script.ScriptModule

validate(export_conf: pytext.config.pytext_config.ExportConfig)[source]
class pytext.torchscript.module.ScriptPyTextEmbeddingModuleIndex(model: torch.jit._script.ScriptModule, tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, index: int = 0)[source]

Bases: pytext.torchscript.module.ScriptPyTextEmbeddingModule

class pytext.torchscript.module.ScriptPyTextEmbeddingModuleWithDense(model: torch.jit._script.ScriptModule, tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, normalizer: pytext.torchscript.tensorizer.normalizer.VectorNormalizer, concat_dense: bool = False)[source]

Bases: pytext.torchscript.module.ScriptPyTextEmbeddingModule

class pytext.torchscript.module.ScriptPyTextEmbeddingModuleWithDenseIndex(model: torch.jit._script.ScriptModule, tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, normalizer: pytext.torchscript.tensorizer.normalizer.VectorNormalizer, index: int = 0, concat_dense: bool = True)[source]

Bases: pytext.torchscript.module.ScriptPyTextEmbeddingModuleWithDense

class pytext.torchscript.module.ScriptPyTextModule(model: torch.jit._script.ScriptModule, output_layer: torch.jit._script.ScriptModule, tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer)[source]

Bases: pytext.torchscript.module.ScriptPyTextEmbeddingModule

class pytext.torchscript.module.ScriptPyTextModuleWithDense(model: torch.jit._script.ScriptModule, output_layer: torch.jit._script.ScriptModule, tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, normalizer: pytext.torchscript.tensorizer.normalizer.VectorNormalizer)[source]

Bases: pytext.torchscript.module.ScriptPyTextEmbeddingModuleWithDense

class pytext.torchscript.module.ScriptPyTextTwoTowerEmbeddingModule(model: torch.jit._script.ScriptModule, right_tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, left_tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer)[source]

Bases: pytext.torchscript.module.ScriptTwoTowerModule

class pytext.torchscript.module.ScriptPyTextTwoTowerEmbeddingModuleWithDense(model: torch.jit._script.ScriptModule, right_tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, left_tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, right_normalizer: pytext.torchscript.tensorizer.normalizer.VectorNormalizer, left_normalizer: pytext.torchscript.tensorizer.normalizer.VectorNormalizer)[source]

Bases: pytext.torchscript.module.ScriptPyTextTwoTowerEmbeddingModule

class pytext.torchscript.module.ScriptPyTextTwoTowerModule(model: torch.jit._script.ScriptModule, output_layer: torch.jit._script.ScriptModule, right_tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, left_tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer)[source]

Bases: pytext.torchscript.module.ScriptTwoTowerModule

class pytext.torchscript.module.ScriptPyTextTwoTowerModuleWithDense(model: torch.jit._script.ScriptModule, output_layer: torch.jit._script.ScriptModule, right_tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, left_tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer, right_normalizer: pytext.torchscript.tensorizer.normalizer.VectorNormalizer, left_normalizer: pytext.torchscript.tensorizer.normalizer.VectorNormalizer)[source]

Bases: pytext.torchscript.module.ScriptPyTextTwoTowerModule

class pytext.torchscript.module.ScriptPyTextVariableSizeEmbeddingModule(model: torch.jit._script.ScriptModule, tensorizer: pytext.torchscript.tensorizer.tensorizer.ScriptTensorizer)[source]

Bases: pytext.torchscript.module.ScriptPyTextEmbeddingModule

Assumes model returns a tuple of representations and sequence lengths, then slices each example’s representation according to length. Returns a list of tensors. The slicing is easier to do outside a traced model.

class pytext.torchscript.module.ScriptTwoTowerModule[source]

Bases: torch.jit._script.ScriptModule

validate(export_conf: pytext.config.pytext_config.ExportConfig)[source]
pytext.torchscript.module.deprecation_warning(export_conf: pytext.config.pytext_config.ExportConfig)[source]

pytext.torchscript.utils module

class pytext.torchscript.utils.ScriptBatchInput[source]

Bases: tuple

A batch of inputs for TorchScript Module(bundle of Tensorizer and Model) texts or tokens is required but multually exclusive :param texts: a batch of raw text inputs :param tokens: a batch of pre-tokenized inputs :param languages: language for each input in the batch

languages

Alias for field number 2

texts

Alias for field number 0

tokens

Alias for field number 1

pytext.torchscript.utils.float_tensor_list1D(input_tensor: torch.Tensor) → List[float][source]

pytext.torchscript.vocab module

class pytext.torchscript.vocab.ScriptVocabulary(vocab_list, unk_idx: int = 0, pad_idx: int = -1, bos_idx: int = -1, eos_idx: int = -1, mask_idx: int = -1, unk_token: Optional[str] = None)[source]

Bases: torch.jit._script.ScriptModule

get_pad_index()[source]
get_unk_index()[source]

Module contents