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))
    
    
    个性签名:时间会解决一切
  • 相关阅读:
    如何规范自己的编程以及软件开发目录(二)
    关于README的内容
    关于编程编程规范以及开发目录的规范性
    第五章:条件、循环以及其他语句(上)
    第四章 当索引行不通时
    python-zipfile模块
    python-shutil模块
    python-sys模块
    python-os模块
    python-threading.Thread(多线程)
  • 原文地址:https://www.cnblogs.com/lfri/p/test.html
Copyright © 2011-2022 走看看