zoukankan      html  css  js  c++  java
  • 测试

    这是一条测试

    我想我会一直孤单,直到老去

    而手动挡收到收到

    • 我们的最终目的是
    • 实现共产主义
    • 为了明天
    • 今天躺下

    哈哈哈

    哈哈哈
    哈哈哈

    哈哈

    哈哈

    哈哈哈

    博客园主题

    点击就送


    点击查看代码
    def hello_world():
        print(hello world)
    

    nnnn 妈的 torch.nn as nn 的 2021-11-18 23:15:50星期四

    \(y = x^2\)

    \[y = 1+2+3+4+5_2 + 6^2 \]

    \[h_{i}^{\prime}=\sigma\left(\frac{1}{K} \sum_{k=1}^{K} \sum_{j \in N_{i}} \alpha_{i j}^{k} W^{k} h_{j}\right) \]

    [========]

    import torch
    import torch.nn as nn
    from torch.utils.tensorboard.summary import text
    from tqdm import tqdm
    from collections import defaultdict
    import config
    from rmseloss import RMSELoss
    import ipdb
    import pandas as pd
    import numpy as np
    
    rmseloss = nn.MSELoss()
    
    def validate(model, validate_loader):
        val_loss = 0
        test_pred = defaultdict(list)
        model.eval()
        for step, batch in tqdm(enumerate(validate_loader)):
            input_ids = batch['input_ids'].to(config.device)
            attention_mask = batch["attention_mask"].to(config.device)
            text = batch['text']
            character = batch['character']
            # target = batch
            with torch.no_grad():
                logists = model(input_ids=input_ids, attention_mask=attention_mask, text=text, character=character)
                val_loss += rmseloss(logists, batch['labels'].to(config.device))
    
        return val_loss / len(validate_loader)
    
    
    def predict(model, test_loader):
        model.eval()
        label_preds = None
        for step, batch in tqdm(enumerate(test_loader)):
            input_ids = batch['input_ids'].to(config.device)
            attention_mask = batch["attention_mask"].to(config.device)
            text = batch['text']
            character = batch['character']
            with torch.no_grad():
                logists = model(input_ids=input_ids, attention_mask=attention_mask, text=text, character=character)
                if label_preds is None:
                    label_preds = logists
                else:
                    label_preds = torch.cat((label_preds, logists), dim=0)
    
        # ipdb.set_trace()
        sub = pd.read_csv('data/submit_example.tsv', sep='\t')
    
        print(len(sub['emotion']))
        sub['emotion'] = label_preds.tolist()
        sub['emotion'] = sub['emotion'].apply(lambda x: ','.join([str(i) for i in x]))
        sub.to_csv(config.res_tsv, sep='\t', index=False)
        print(sub.head(5))
    
    
    个性签名:时间会解决一切
  • 相关阅读:
    jQuery层级选择器
    jQuery基本选择器
    What is the difference between try/except and assert?
    glove 安装错误
    Windows10+anaconda,python3.5, 安装glove-python
    GloVe:另一种Word Embedding方法
    PyTorch在NLP任务中使用预训练词向量
    理解GloVe模型(Global vectors for word representation)
    word2vec 中的数学原理详解(二)预备知识
    Python zip() 函数
  • 原文地址:https://www.cnblogs.com/lfri/p/test.html
Copyright © 2011-2022 走看看