Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

数据集预处理出错 #160

Open
heweibuzhihuo opened this issue Oct 29, 2023 · 4 comments
Open

数据集预处理出错 #160

heweibuzhihuo opened this issue Oct 29, 2023 · 4 comments

Comments

@heweibuzhihuo
Copy link

采用data/cnews_loader.py进行数据集预处理的时候代码无法正常运行,会是什么原因,是我的调用代码存在问题吗

@niumaaba
Copy link

我们通过cnews_loader.py来进行数据集预处理,该类中给出了所有需要使用的方法,我们只需要进行相应的调用即可。
首先,使用read_file(filename)方法读取训练集、验证集和测试集的内容和标签。

image

接下来,可以使用build_vocab(train_dir, vocab_dir, vocab_size=5000)方法构建词汇表,并存储到指定的文件中。

image

然后,使用read_vocab(vocab_dir)方法读取词汇表,获取词汇列表和词汇到id的映射。

image

接着,使用read_category()方法读取分类目录,获取分类列表和分类到id的映射。

image

现在,可以使用process_file(filename, word_to_id, cat_to_id, max_length=600)方法将训练集、验证集和测试集转换为id表示。

image

最后,可以使用batch_iter(x, y, batch_size=64)方法生成训练数据的批次。

image

通过以上步骤,我们便可以完成数据的读取、词汇表的构建、文本的转换和批次数据的生成。
随后运行相应的代码,便可得到词汇表,并数据集预处理完毕

@heweibuzhihuo
Copy link
Author

在运行run_cnn.py时总会出现各种报错,我查询之后发现是TensorFlow版本不一致,该如何解决呢

@niumaaba
Copy link

我在运行时也曾出现过这样的问题,你可以尝试下载低版本的TensorFlow来解决这个问题。但目前低版本的TensorFlow很难直接下载,所以你可能需要采取使用虚拟环境等多种方式,你也可能对其代码进行修改,将低版本的代码更换为高版本的代码,这两种方式你都可以进行一定的尝试

@hxhalym
Copy link

hxhalym commented Oct 30, 2023

这个项目可以在windows平台运行吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants