flambe.field.label

Module Contents

class flambe.field.label.LabelField(one_hot: bool = False, multilabel_sep: Optional[str] = None, labels: Optional[Union[Iterable[str], str]] = None)[source]

Bases: flambe.field.field.Field

Featurizes input labels.

The class also handles multilabel inputs and one hot encoding.

vocab_list :List[str][source]

Get the list of tokens in the vocabulary.

Returns:The list of tokens in the vocabulary, ordered.
Return type:List[str]
vocab_size :int[source]

Get the vocabulary length.

Returns:The length of the vocabulary
Return type:int
label_count :torch.Tensor[source]

Get the label count.

Returns:Tensor containing the count for each label, indexed by the id of the label in the vocabulary.
Return type:torch.Tensor
label_freq :torch.Tensor[source]

Get the frequency of each label.

Returns:Tensor containing the frequency of each label, indexed by the id of the label in the vocabulary.
Return type:torch.Tensor
label_inv_freq :torch.Tensor[source]

Get the inverse frequency for each label.

Returns:Tensor containing the inverse frequency of each label, indexed by the id of the label in the vocabulary.
Return type:torch.Tensor
setup(self, *data: np.ndarray)[source]

Build the vocabulary.

Parameters:data (Iterable[str]) – List of input strings.
process(self, example)[source]

Featurize a single example.

Parameters:example (str) – The input label
Returns:A list of integer tokens
Return type:torch.Tensor