當前位置: 首頁>>代碼示例>>Python>>正文


Python field.Field方法代碼示例

本文整理匯總了Python中allennlp.data.fields.field.Field方法的典型用法代碼示例。如果您正苦於以下問題:Python field.Field方法的具體用法?Python field.Field怎麽用?Python field.Field使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在allennlp.data.fields.field的用法示例。


在下文中一共展示了field.Field方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: as_tensor_dict

# 需要導入模塊: from allennlp.data.fields import field [as 別名]
# 或者: from allennlp.data.fields.field import Field [as 別名]
def as_tensor_dict(
        self, padding_lengths: Dict[str, Dict[str, int]] = None
    ) -> Dict[str, DataArray]:
        """
        Pads each `Field` in this instance to the lengths given in `padding_lengths` (which is
        keyed by field name, then by padding key, the same as the return value in
        :func:`get_padding_lengths`), returning a list of torch tensors for each field.

        If `padding_lengths` is omitted, we will call `self.get_padding_lengths()` to get the
        sizes of the tensors to create.
        """
        padding_lengths = padding_lengths or self.get_padding_lengths()
        tensors = {}
        for field_name, field in self.fields.items():
            tensors[field_name] = field.as_tensor(padding_lengths[field_name])
        return tensors 
開發者ID:allenai,項目名稱:allennlp,代碼行數:18,代碼來源:instance.py

示例2: as_tensor_dict

# 需要導入模塊: from allennlp.data.fields import field [as 別名]
# 或者: from allennlp.data.fields.field import Field [as 別名]
def as_tensor_dict(self,
                       padding_lengths                            = None,
                       cuda_device      = -1)                        :
        u"""
        Pads each ``Field`` in this instance to the lengths given in ``padding_lengths`` (which is
        keyed by field name, then by padding key, the same as the return value in
        :func:`get_padding_lengths`), returning a list of torch tensors for each field.

        If ``padding_lengths`` is omitted, we will call ``self.get_padding_lengths()`` to get the
        sizes of the tensors to create.
        """
        padding_lengths = padding_lengths or self.get_padding_lengths()
        tensors = {}
        for field_name, field in list(self.fields.items()):
            tensors[field_name] = field.as_tensor(padding_lengths[field_name],
                                                  cuda_device=cuda_device)
        return tensors 
開發者ID:plasticityai,項目名稱:magnitude,代碼行數:19,代碼來源:instance.py

示例3: __init__

# 需要導入模塊: from allennlp.data.fields import field [as 別名]
# 或者: from allennlp.data.fields.field import Field [as 別名]
def __init__(self, fields: MutableMapping[str, Field]) -> None:
        self.fields = fields
        self.indexed = False

    # Add methods for `Mapping`.  Note, even though the fields are
    # mutable, we don't implement `MutableMapping` because we want
    # you to use `add_field` and supply a vocabulary. 
開發者ID:allenai,項目名稱:allennlp,代碼行數:9,代碼來源:instance.py

示例4: __getitem__

# 需要導入模塊: from allennlp.data.fields import field [as 別名]
# 或者: from allennlp.data.fields.field import Field [as 別名]
def __getitem__(self, key: str) -> Field:
        return self.fields[key] 
開發者ID:allenai,項目名稱:allennlp,代碼行數:4,代碼來源:instance.py

示例5: add_field

# 需要導入模塊: from allennlp.data.fields import field [as 別名]
# 或者: from allennlp.data.fields.field import Field [as 別名]
def add_field(self, field_name: str, field: Field, vocab: Vocabulary = None) -> None:
        """
        Add the field to the existing fields mapping.
        If we have already indexed the Instance, then we also index `field`, so
        it is necessary to supply the vocab.
        """
        self.fields[field_name] = field
        if self.indexed:
            field.index(vocab) 
開發者ID:allenai,項目名稱:allennlp,代碼行數:11,代碼來源:instance.py

示例6: get_padding_lengths

# 需要導入模塊: from allennlp.data.fields import field [as 別名]
# 或者: from allennlp.data.fields.field import Field [as 別名]
def get_padding_lengths(self) -> Dict[str, Dict[str, int]]:
        """
        Returns a dictionary of padding lengths, keyed by field name.  Each `Field` returns a
        mapping from padding keys to actual lengths, and we just key that dictionary by field name.
        """
        lengths = {}
        for field_name, field in self.fields.items():
            lengths[field_name] = field.get_padding_lengths()
        return lengths 
開發者ID:allenai,項目名稱:allennlp,代碼行數:11,代碼來源:instance.py

示例7: __iter__

# 需要導入模塊: from allennlp.data.fields import field [as 別名]
# 或者: from allennlp.data.fields.field import Field [as 別名]
def __iter__(self) -> Iterator[Field]:
        return iter(self.field_list) 
開發者ID:allenai,項目名稱:allennlp,代碼行數:4,代碼來源:list_field.py

示例8: __getitem__

# 需要導入模塊: from allennlp.data.fields import field [as 別名]
# 或者: from allennlp.data.fields.field import Field [as 別名]
def __getitem__(self, idx: int) -> Field:
        return self.field_list[idx] 
開發者ID:allenai,項目名稱:allennlp,代碼行數:4,代碼來源:list_field.py

示例9: get_padding_lengths

# 需要導入模塊: from allennlp.data.fields import field [as 別名]
# 或者: from allennlp.data.fields.field import Field [as 別名]
def get_padding_lengths(self)                             :
        u"""
        Returns a dictionary of padding lengths, keyed by field name.  Each ``Field`` returns a
        mapping from padding keys to actual lengths, and we just key that dictionary by field name.
        """
        lengths = {}
        for field_name, field in list(self.fields.items()):
            lengths[field_name] = field.get_padding_lengths()
        return lengths 
開發者ID:plasticityai,項目名稱:magnitude,代碼行數:11,代碼來源:instance.py

示例10: __init__

# 需要導入模塊: from allennlp.data.fields import field [as 別名]
# 或者: from allennlp.data.fields.field import Field [as 別名]
def __init__(self, field_dict: Dict[str, Field]) -> None:
        self.field_dict = field_dict 
開發者ID:allenai,項目名稱:kb,代碼行數:4,代碼來源:dict_field.py


注:本文中的allennlp.data.fields.field.Field方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。