资源及教程来自伯禹教育
先写一个简易的实现
import sys
import re
import os
import time
import torch as tc
import numpy as np
import torchvision as tv
import torchvision.transforms as transforms
from torch import nn, optim
from torch.nn import functional as F
from matplotlib import pyplot as plt
from torch.utils.data import DataLoader, TensorDataset
import collections
def load_data_jay_lyrics():
""" 读取歌词,返回文章所有字的索引,词对索引的映射,索引对词的映射,字典大小 """
with open('./data/歌词.txt', encoding='utf8', mode='r') as f:
corpus_chars = f.read()
corpus_chars = corpus_chars.replace('\n', ' ').replace('\r', ' ')
corpus_chars = corpus_chars[0:10000]
idx_to_char = list(set(corpus_chars)