测试

这是一条测试

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

而手动挡收到收到

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

哈哈哈

哈哈哈
哈哈哈

哈哈

哈哈

哈哈哈

博客园主题

点击就送


点击查看代码
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))

posted @ 2021-11-18 23:18  Rogn  阅读(78)  评论(0编辑  收藏  举报