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


Python vocab.items方法代碼示例

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


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

示例1: _load_fields

# 需要導入模塊: from torchtext import vocab [as 別名]
# 或者: from torchtext.vocab import items [as 別名]
def _load_fields(dataset, data_type, opt, checkpoint):
    if checkpoint is not None:
        logger.info('Loading vocab from checkpoint at %s.' % opt.train_from)
        fields = load_fields_from_vocab(
            checkpoint['vocab'], data_type)
    else:
        fields = load_fields_from_vocab(
            torch.load(opt.data + '.vocab.pt'), data_type)
    fields = dict([(k, f) for (k, f) in fields.items()
                   if k in dataset.examples[0].__dict__])

    if data_type == 'text':
        logger.info(' * vocabulary size. source = %d; target = %d; template = %d'%
                    (len(fields['src'].vocab), len(fields['tgt'].vocab),len(fields['template'].vocab)))
    else:
        logger.info(' * vocabulary size. target = %d' %
                    (len(fields['tgt'].vocab)))

    return fields 
開發者ID:InitialBug,項目名稱:BiSET,代碼行數:21,代碼來源:inputter.py

示例2: load_fields_from_vocab

# 需要導入模塊: from torchtext import vocab [as 別名]
# 或者: from torchtext.vocab import items [as 別名]
def load_fields_from_vocab(vocab, data_type="text"):
    """
    Load Field objects from `vocab.pt` file.
    """
    vocab = dict(vocab)
    n_src_features = len(collect_features(vocab, 'src'))
    n_tgt_features = len(collect_features(vocab, 'tgt'))
    fields = get_fields(data_type, n_src_features, n_tgt_features)
    for k, v in vocab.items():
        # Hack. Can't pickle defaultdict :(
        v.stoi = defaultdict(lambda: 0, v.stoi)
        fields[k].vocab = v
    return fields 
開發者ID:xiadingZ,項目名稱:video-caption-openNMT.pytorch,代碼行數:15,代碼來源:IO.py

示例3: save_fields_to_vocab

# 需要導入模塊: from torchtext import vocab [as 別名]
# 或者: from torchtext.vocab import items [as 別名]
def save_fields_to_vocab(fields):
    """
    Save Vocab objects in Field objects to `vocab.pt` file.
    """
    vocab = []
    for k, f in fields.items():
        if f is not None and 'vocab' in f.__dict__:
            f.vocab.stoi = dict(f.vocab.stoi)
            vocab.append((k, f.vocab))
    return vocab 
開發者ID:xiadingZ,項目名稱:video-caption-openNMT.pytorch,代碼行數:12,代碼來源:IO.py

示例4: join_dicts

# 需要導入模塊: from torchtext import vocab [as 別名]
# 或者: from torchtext.vocab import items [as 別名]
def join_dicts(*args):
    """
    args: dictionaries with disjoint keys
    returns: a single dictionary that has the union of these keys
    """
    return dict(chain(*[d.items() for d in args])) 
開發者ID:prezaei85,項目名稱:nl2sql,代碼行數:8,代碼來源:IO.py

示例5: load_fields

# 需要導入模塊: from torchtext import vocab [as 別名]
# 或者: from torchtext.vocab import items [as 別名]
def load_fields(vocab):
        vocab = dict(vocab)
        fields = TableDataset.get_fields()
        for k, v in vocab.items():
            # Hack. Can't pickle defaultdict :(
            v.stoi = defaultdict(lambda: 0, v.stoi)
            fields[k].vocab = v
        return fields 
開發者ID:prezaei85,項目名稱:nl2sql,代碼行數:10,代碼來源:IO.py

示例6: save_vocab

# 需要導入模塊: from torchtext import vocab [as 別名]
# 或者: from torchtext.vocab import items [as 別名]
def save_vocab(fields):
        vocab = []
        for k, f in fields.items():
            if 'vocab' in f.__dict__:
                f.vocab.stoi = dict(f.vocab.stoi)
                vocab.append((k, f.vocab))
        return vocab 
開發者ID:prezaei85,項目名稱:nl2sql,代碼行數:9,代碼來源:IO.py

示例7: load_fields

# 需要導入模塊: from torchtext import vocab [as 別名]
# 或者: from torchtext.vocab import items [as 別名]
def load_fields(vocab):
        vocab = dict(vocab)
        fields = ONMTDataset.get_fields(len(ONMTDataset.collect_features(vocab)))
        for k, v in vocab.items():
            # Hack. Can't pickle defaultdict :(
            v.stoi = defaultdict(lambda: 0, v.stoi)
            fields[k].vocab = v
        return fields 
開發者ID:antspy,項目名稱:quantized_distillation,代碼行數:10,代碼來源:IO.py

示例8: save_fields_to_vocab

# 需要導入模塊: from torchtext import vocab [as 別名]
# 或者: from torchtext.vocab import items [as 別名]
def save_fields_to_vocab(fields):
    """
    Save Vocab objects in Field objects to `vocab.pt` file.
    """
    vocab = []
    for k, f in fields.items():
        if 'vocab' in f.__dict__:
            f.vocab.stoi = dict(f.vocab.stoi)
            vocab.append((k, f.vocab))
    return vocab 
開發者ID:moonlightlane,項目名稱:QG-Net,代碼行數:12,代碼來源:IO.py

示例9: _join_dicts

# 需要導入模塊: from torchtext import vocab [as 別名]
# 或者: from torchtext.vocab import items [as 別名]
def _join_dicts(*args):
    """
    Args:
        dictionaries with disjoint keys.
    Returns:
        a single dictionary that has the union of these keys.
    """
    return dict(chain(*[d.items() for d in args])) 
開發者ID:moonlightlane,項目名稱:QG-Net,代碼行數:10,代碼來源:IO.py

示例10: filter_counter

# 需要導入模塊: from torchtext import vocab [as 別名]
# 或者: from torchtext.vocab import items [as 別名]
def filter_counter(freqs, min_freq):
    cnt = Counter()
    for k, v in freqs.items():
        if (min_freq is None) or (v >= min_freq):
            cnt[k] = v
    return cnt 
開發者ID:donglixp,項目名稱:coarse2fine,代碼行數:8,代碼來源:IO.py


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