lucaprot multi class 建模问题咨询
Lucaprot团队的老师们好
我想使用lucaprot构建一个multi class的模型。在二分类模型的基础上,我修改了对应的csv文件(如图1所示),同时在label.txt文件中加上了新增的label id,但几次尝试都以报错告终(错误提示如下2),建模代码见3。想请教老师们,是不是我遗漏了哪些要点,导致建模失败。
btw,我注意到之前有同学也请教过如何训练多分类模型,有老师推荐了lucanone模型(已★★★)。不过我是在云服务器上开展的任务,换新的模型可能有大量的数据转移工作,所以目前还是想基于lucaprot模型进行multi class预测,望老师们不吝赐教。
图1
错误提示2:
Traceback (most recent call last):
File "/root/autodl-tmp/3-opt/lucaprot/src/run.py", line 827, in
建模代码3: #!/bin/bash
export CUDA_VISIBLE_DEVICES=0
DATASET_NAME="tf_predict" DATASET_TYPE="protein" TASK_TYPE="multi_class"
sequence + structural embeddding
MODEL_TYPE="sefn" CONFIG_NAME="sefn_config.json" INPUT_MODE="single" LABEL_TYPE="TF" embedding_input_size=2560 embedding_type="matrix" SEQ_MAX_LENGTH="500" embedding_max_length="2048" TRUNCT_TYPE="right"
none, max, value_attention
SEQ_POOLING_TYPE="value_attention"
max, value_attention
embedding_pooling_type="value_attention" VOCAB_NAME="subword_100.txt" SUBWORD_CODES_NAME="tf_100_codes.txt" MAX_METRIC_TYPE="f1" time_str=$(date "+%Y%m%d%H%M%S")
python run.py
--data_dir /root/autodl-tmp/3-opt/lucaprot/dataset/predict/protein/binary_class
--tfrecords
--filename_pattern {}_with_pdb_emb.csv
--dataset_name $DATASET_NAME
--dataset_type $DATASET_TYPE
--task_type $TASK_TYPE
--model_type $MODEL_TYPE
--subword
--codes_file /root/autodl-tmp/1-data/lucatf_multi_label/test/100_codes.txt
--input_mode $INPUT_MODE
--label_type $LABEL_TYPE
--label_filepath /root/autodl-tmp/3-opt/lucaprot/dataset/predict/protein/binary_class/label.test.txt
--output_dir ../models/$DATASET_NAME/$DATASET_TYPE/$TASK_TYPE/$MODEL_TYPE/$time_str
--log_dir ../logs/$DATASET_NAME/$DATASET_TYPE/$TASK_TYPE/$MODEL_TYPE/$time_str
--tb_log_dir ../tb-logs/$DATASET_NAME/$DATASET_TYPE/$TASK_TYPE/$MODEL_TYPE/$time_str
--config_path ../config/rdrp_40_extend/protein/binary_class/sefn_config.json
--seq_vocab_path /root/autodl-tmp/1-data/lucatf_multi_label/test/subword_100.txt
--seq_pooling_type $SEQ_POOLING_TYPE
--embedding_pooling_type $embedding_pooling_type
--do_train
--do_eval
--do_predict
--evaluate_during_training
--per_gpu_train_batch_size=16
--per_gpu_eval_batch_size=16
--gradient_accumulation_steps=1
--learning_rate=1e-4
--num_train_epochs=1
--logging_steps=100
--save_steps=100
--overwrite_output_dir
--loss_type cce
--max_metric_type $MAX_METRIC_TYPE
--seq_max_length=$SEQ_MAX_LENGTH
--embedding_max_length=$embedding_max_length
--trunc_type=$TRUNCT_TYPE
--no_token_type_embeddings
--embedding_input_size $embedding_input_size
--embedding_type $embedding_type
--shuffle_queue_size 5000
--save_all
谢谢!
Lucaprot团队的老师们好
我想使用lucaprot构建一个multi class的模型。在二分类模型的基础上,我修改了对应的csv文件(如图1所示),同时在label.txt文件中加上了新增的label id,但几次尝试都以报错告终(错误提示如下2),建模代码见3。想请教老师们,是不是我遗漏了哪些要点,导致建模失败。
btw,我注意到之前有同学也请教过如何训练多分类模型,有老师推荐了lucanone模型(已★★★)。不过我是在云服务器上开展的任务,换新的模型可能有大量的数据转移工作,所以目前还是想基于lucaprot模型进行multi class预测,望老师们不吝赐教。
图1
错误提示2: Traceback (most recent call last): File "/root/autodl-tmp/3-opt/lucaprot/src/run.py", line 827, in main() File "/root/autodl-tmp/3-opt/lucaprot/src/run.py", line 753, in main global_step, tr_loss, max_metric_model_info = train( File "/root/autodl-tmp/3-opt/lucaprot/src/trainer.py", line 309, in train _, _, test_result = predict( File "/root/autodl-tmp/3-opt/lucaprot/src/predictor.py", line 155, in predict true_label_names = [label_list[idx] for idx in out_label_ids] File "/root/autodl-tmp/3-opt/lucaprot/src/predictor.py", line 155, in true_label_names = [label_list[idx] for idx in out_label_ids] TypeError: only integer scalar arrays can be converted to a scalar index
建模代码3: #!/bin/bash
export CUDA_VISIBLE_DEVICES=0
DATASET_NAME="tf_predict" DATASET_TYPE="protein" TASK_TYPE="multi_class"
sequence + structural embeddding
MODEL_TYPE="sefn" CONFIG_NAME="sefn_config.json" INPUT_MODE="single" LABEL_TYPE="TF" embedding_input_size=2560 embedding_type="matrix" SEQ_MAX_LENGTH="500" embedding_max_length="2048" TRUNCT_TYPE="right"
none, max, value_attention
SEQ_POOLING_TYPE="value_attention"
max, value_attention
embedding_pooling_type="value_attention" VOCAB_NAME="subword_100.txt" SUBWORD_CODES_NAME="tf_100_codes.txt" MAX_METRIC_TYPE="f1" time_str=$(date "+%Y%m%d%H%M%S")
python run.py --data_dir /root/autodl-tmp/3-opt/lucaprot/dataset/predict/protein/binary_class --tfrecords --filename_pattern {}_with_pdb_emb.csv --dataset_name $DATASET_NAME --dataset_type $DATASET_TYPE --task_type $TASK_TYPE --model_type $MODEL_TYPE --subword --codes_file /root/autodl-tmp/1-data/lucatf_multi_label/test/100_codes.txt --input_mode $INPUT_MODE --label_type $LABEL_TYPE --label_filepath /root/autodl-tmp/3-opt/lucaprot/dataset/predict/protein/binary_class/label.test.txt --output_dir ../models/$DATASET_NAME/$DATASET_TYPE/$TASK_TYPE/$MODEL_TYPE/$time_str --log_dir ../logs/$DATASET_NAME/$DATASET_TYPE/$TASK_TYPE/$MODEL_TYPE/$time_str --tb_log_dir ../tb-logs/$DATASET_NAME/$DATASET_TYPE/$TASK_TYPE/$MODEL_TYPE/$time_str --config_path ../config/rdrp_40_extend/protein/binary_class/sefn_config.json --seq_vocab_path /root/autodl-tmp/1-data/lucatf_multi_label/test/subword_100.txt --seq_pooling_type $SEQ_POOLING_TYPE --embedding_pooling_type $embedding_pooling_type --do_train --do_eval --do_predict --evaluate_during_training --per_gpu_train_batch_size=16 --per_gpu_eval_batch_size=16 --gradient_accumulation_steps=1 --learning_rate=1e-4 --num_train_epochs=1 --logging_steps=100 --save_steps=100 --overwrite_output_dir --loss_type cce --max_metric_type $MAX_METRIC_TYPE --seq_max_length=$SEQ_MAX_LENGTH --embedding_max_length=$embedding_max_length --trunc_type=$TRUNCT_TYPE --no_token_type_embeddings --embedding_input_size $embedding_input_size --embedding_type $embedding_type --shuffle_queue_size 5000 --save_all
谢谢!
总共多少个类别? 看一下dataset下的label.txt这个文件
数据集csv中label是0到n-1的label index,其中n为分类个数 label.txt中存放的是label index对应的class name,行号就是该行class name对应的label index 比如三分类,csv中分别是label字段就是0,1,2其中的一个 三个类别的名称是A,B,C,那么label.txt中的内容就是 A B C 第0行是类别的名字A,label index是0 第1行是类别的名字B,label index是1 第2行是类别的名字C,label index是2
LucaOne team 的老师您好
1、我上午用了一个小样本测试,包括阴性数据设了9个分类。label.test.txt内容如下:
cat label.test.txt
label NTF A B C D E F G H
2、同时我还修改了配置文件sefn_config.json,将 "num_labels": 设为了9。 但是运行建模脚本还是报错
loss 2.16663: : 999it [46:24, 2.79s/it]
Epoch: 0%| | 0/1 [46:24<?, ?it/s]
Traceback (most recent call last):
File "/root/autodl-tmp/3-opt/lucaprot/src/run.py", line 827, in
3、CSV文件如下所示,multi_class 的最后一列source需要改变么?
LucaOne team 的老师您好
1、我上午用了一个小样本测试,包括阴性数据设了9个分类。label.test.txt内容如下:
cat label.test.txt
label NTF A B C D E F G H
2、同时我还修改了配置文件sefn_config.json,将 "num_labels": 设为了9。 但是运行建模脚本还是报错
loss 2.16663: : 999it [46:24, 2.79s/it] Epoch: 0%| | 0/1 [46:24<?, ?it/s] Traceback (most recent call last): File "/root/autodl-tmp/3-opt/lucaprot/src/run.py", line 827, in main() File "/root/autodl-tmp/3-opt/lucaprot/src/run.py", line 753, in main global_step, tr_loss, max_metric_model_info = train( File "/root/autodl-tmp/3-opt/lucaprot/src/trainer.py", line 309, in train _, _, test_result = predict( File "/root/autodl-tmp/3-opt/lucaprot/src/predictor.py", line 155, in predict true_label_names = [label_list[idx] for idx in out_label_ids] File "/root/autodl-tmp/3-opt/lucaprot/src/predictor.py", line 155, in true_label_names = [label_list[idx] for idx in out_label_ids] TypeError: only integer scalar arrays can be converted to a scalar index
3、CSV文件如下所示,multi_class 的最后一列source需要改变么?
你在代码155行(也就是这句true_label_names = [label_list[idx] for idx in out_label_ids])之前插入两句: print(out_label_ids) input("continue:") 看下输出什么: File "/root/autodl-tmp/3-opt/lucaprot/src/predictor.py", line 155, in true_label_names = [label_list[idx] for idx in out_label_ids]
在predictor.py脚本155行插入了 print(out_label_ids) input("continue:")
信息提示如下:
2025/04/26 15:33:40-INFO-predictor | ***** Running test checkpoint-1000 *****
2025/04/26 15:33:40-INFO-predictor | Num examples = 8
2025/04/26 15:33:40-INFO-predictor | Batch size = 16
Testing: 246it [07:11, 1.75s/it]
[[1]
[0]ing: 245it [07:11, 3.73it/s]
[0]
...
[0]
[0]
[0]]
continue:
loss 2.16663: : 999it [47:51, 2.87s/it]
Epoch: 0%| | 0/1 [47:51<?, ?it/s]
Traceback (most recent call last):
File "/root/autodl-tmp/3-opt/lucaprot/src/run.py", line 827, in
在predictor.py脚本155行插入了 print(out_label_ids) input("continue:")
信息提示如下: 2025/04/26 15:33:40-INFO-predictor | ***** Running test checkpoint-1000 ***** 2025/04/26 15:33:40-INFO-predictor | Num examples = 8 2025/04/26 15:33:40-INFO-predictor | Batch size = 16 Testing: 246it [07:11, 1.75s/it] [[1] [0]ing: 245it [07:11, 3.73it/s] [0] ... [0] [0] [0]] continue: loss 2.16663: : 999it [47:51, 2.87s/it] Epoch: 0%| | 0/1 [47:51<?, ?it/s] Traceback (most recent call last): File "/root/autodl-tmp/3-opt/lucaprot/src/run.py", line 827, in main() File "/root/autodl-tmp/3-opt/lucaprot/src/run.py", line 753, in main global_step, tr_loss, max_metric_model_info = train( File "/root/autodl-tmp/3-opt/lucaprot/src/trainer.py", line 309, in train _, _, test_result = predict( File "/root/autodl-tmp/3-opt/lucaprot/src/predictor.py", line 157, in predict true_label_names = [label_list[idx] for idx in out_label_ids] File "/root/autodl-tmp/3-opt/lucaprot/src/predictor.py", line 157, in true_label_names = [label_list[idx] for idx in out_label_ids] TypeError: only integer scalar arrays can be converted to a scalar index 你看一下,你这个是多分类,但是这个打印出来全部是0或者1吗
我的label.txt和.CSV文件中都用了多个标签,回头看了一下建模的脚本,这个参数是不是也要对应修改呢?
label_type: str, the label type name, such as "rdrp"
之前做二分类建模时,label_type 我填的.CSV文件中source列的内容,现在做多分类建模,是不是也要对应修改才行。
我的label.txt和.CSV文件中都用了多个标签,回头看了一下建模的脚本,这个参数是不是也要对应修改呢?
label_type: str, the label type name, such as "rdrp"
之前做二分类建模时,label_type 我填的.CSV文件中source列的内容,现在做多分类建模,是不是也要对应修改才行。
稍等,我review一下代码
我的label.txt和.CSV文件中都用了多个标签,回头看了一下建模的脚本,这个参数是不是也要对应修改呢?
label_type: str, the label type name, such as "rdrp"
之前做二分类建模时,label_type 我填的.CSV文件中source列的内容,现在做多分类建模,是不是也要对应修改才行。
你重新下载试试,我优化了代码
好的,我再试试,谢谢。
好的,我再试试,谢谢。
running 正常吗
今天重新安装了更新后的lucaprot,使用以下代码测试了小样本的multi_class 建模,还是有点问题。
原始代码: export CUDA_VISIBLE_DEVICES=0
DATASET_NAME="tf_predict" DATASET_TYPE="protein" TASK_TYPE="multi_class"
sequence + structural embeddding
MODEL_TYPE="sefn" CONFIG_NAME="0425_sefn_config.json" INPUT_MODE="single" LABEL_TYPE="TF" embedding_input_size=2560 embedding_type="matrix" SEQ_MAX_LENGTH="100" embedding_max_length="2048" TRUNCT_TYPE="right"
none, max, value_attention
SEQ_POOLING_TYPE="value_attention"
max, value_attention
embedding_pooling_type="value_attention" VOCAB_NAME="subword_100.txt" SUBWORD_CODES_NAME="tf_100_codes.txt" MAX_METRIC_TYPE="f1" time_str=$(date "+%Y%m%d%H%M%S")
python run.py
--data_dir /root/autodl-tmp/3-opt/0428_lucaprot/LucaProt/dataset/tf_predict/protein/multi_class
--tfrecords
--filename_pattern {}_with_pdb_emb.csv
--dataset_name $DATASET_NAME
--dataset_type $DATASET_TYPE
--task_type $TASK_TYPE
--model_type $MODEL_TYPE
--subword
--codes_file /root/autodl-tmp/1-data/lucatf_multi_label/test/tf_100_codes.txt
--input_mode $INPUT_MODE
--label_type $LABEL_TYPE
--label_filepath /root/autodl-tmp/3-opt/0428_lucaprot/LucaProt/dataset/tf_predict/protein/multi_class/label.txt
--output_dir ../models/$DATASET_NAME/$DATASET_TYPE/$TASK_TYPE/$MODEL_TYPE/$time_str
--log_dir ../logs/$DATASET_NAME/$DATASET_TYPE/$TASK_TYPE/$MODEL_TYPE/$time_str
--tb_log_dir ../tb-logs/$DATASET_NAME/$DATASET_TYPE/$TASK_TYPE/$MODEL_TYPE/$time_str
--config_path ./0425_sefn_config.json
--seq_vocab_path /root/autodl-tmp/1-data/lucatf_multi_label/test/subword_100.txt
--seq_pooling_type $SEQ_POOLING_TYPE
--embedding_pooling_type $embedding_pooling_type
--do_train
--do_eval
--do_predict
--evaluate_during_training
--per_gpu_train_batch_size=16
--per_gpu_eval_batch_size=16
--gradient_accumulation_steps=1
--learning_rate=1e-4
--num_train_epochs=1
--logging_steps=1000
--save_steps=1000
--overwrite_output_dir
--loss_type cce
--max_metric_type $MAX_METRIC_TYPE
--seq_max_length=$SEQ_MAX_LENGTH
--embedding_max_length=$embedding_max_length
--trunc_type=$TRUNCT_TYPE
--no_token_type_embeddings
--embedding_input_size $embedding_input_size
--embedding_type $embedding_type
--shuffle_queue_size 1000
--save_all
报错信息:
今天重新安装了更新后的lucaprot,使用以下代码测试了小样本的multi_class 建模,还是有点问题。
原始代码: export CUDA_VISIBLE_DEVICES=0
DATASET_NAME="tf_predict" DATASET_TYPE="protein" TASK_TYPE="multi_class"
sequence + structural embeddding
MODEL_TYPE="sefn" CONFIG_NAME="0425_sefn_config.json" INPUT_MODE="single" LABEL_TYPE="TF" embedding_input_size=2560 embedding_type="matrix" SEQ_MAX_LENGTH="100" embedding_max_length="2048" TRUNCT_TYPE="right"
none, max, value_attention
SEQ_POOLING_TYPE="value_attention"
max, value_attention
embedding_pooling_type="value_attention" VOCAB_NAME="subword_100.txt" SUBWORD_CODES_NAME="tf_100_codes.txt" MAX_METRIC_TYPE="f1" time_str=$(date "+%Y%m%d%H%M%S")
python run.py
--data_dir /root/autodl-tmp/3-opt/0428_lucaprot/LucaProt/dataset/tf_predict/protein/multi_class
--tfrecords
--filename_pattern {}_with_pdb_emb.csv
--dataset_name $DATASET_NAME
--dataset_type $DATASET_TYPE
--task_type $TASK_TYPE
--model_type $MODEL_TYPE
--subword
--codes_file /root/autodl-tmp/1-data/lucatf_multi_label/test/tf_100_codes.txt
--input_mode $INPUT_MODE
--label_type $LABEL_TYPE
--label_filepath /root/autodl-tmp/3-opt/0428_lucaprot/LucaProt/dataset/tf_predict/protein/multi_class/label.txt
--output_dir ../models/$DATASET_NAME/$DATASET_TYPE/$TASK_TYPE/$MODEL_TYPE/$time_str
--log_dir ../logs/$DATASET_NAME/$DATASET_TYPE/$TASK_TYPE/$MODEL_TYPE/$time_str
--tb_log_dir ../tb-logs/$DATASET_NAME/$DATASET_TYPE/$TASK_TYPE/$MODEL_TYPE/$time_str
--config_path ./0425_sefn_config.json
--seq_vocab_path /root/autodl-tmp/1-data/lucatf_multi_label/test/subword_100.txt
--seq_pooling_type $SEQ_POOLING_TYPE
--embedding_pooling_type $embedding_pooling_type
--do_train
--do_eval
--do_predict
--evaluate_during_training
--per_gpu_train_batch_size=16
--per_gpu_eval_batch_size=16
--gradient_accumulation_steps=1
--learning_rate=1e-4
--num_train_epochs=1
--logging_steps=1000
--save_steps=1000
--overwrite_output_dir
--loss_type cce
--max_metric_type $MAX_METRIC_TYPE
--seq_max_length=$SEQ_MAX_LENGTH
--embedding_max_length=$embedding_max_length
--trunc_type=$TRUNCT_TYPE
--no_token_type_embeddings
--embedding_input_size $embedding_input_size
--embedding_type $embedding_type
--shuffle_queue_size 1000
--save_all报错信息:
我知道问题所在了,明天给你搞下,单卡与多卡要写个if else
今天重新安装了更新后的lucaprot,使用以下代码测试了小样本的multi_class 建模,还是有点问题。
原始代码: export CUDA_VISIBLE_DEVICES=0
DATASET_NAME="tf_predict" DATASET_TYPE="protein" TASK_TYPE="multi_class"
sequence + structural embeddding
MODEL_TYPE="sefn" CONFIG_NAME="0425_sefn_config.json" INPUT_MODE="single" LABEL_TYPE="TF" embedding_input_size=2560 embedding_type="matrix" SEQ_MAX_LENGTH="100" embedding_max_length="2048" TRUNCT_TYPE="right"
none, max, value_attention
SEQ_POOLING_TYPE="value_attention"
max, value_attention
embedding_pooling_type="value_attention" VOCAB_NAME="subword_100.txt" SUBWORD_CODES_NAME="tf_100_codes.txt" MAX_METRIC_TYPE="f1" time_str=$(date "+%Y%m%d%H%M%S")
python run.py --data_dir /root/autodl-tmp/3-opt/0428_lucaprot/LucaProt/dataset/tf_predict/protein/multi_class --tfrecords --filename_pattern {}_with_pdb_emb.csv --dataset_name $DATASET_NAME --dataset_type $DATASET_TYPE --task_type $TASK_TYPE --model_type $MODEL_TYPE --subword --codes_file /root/autodl-tmp/1-data/lucatf_multi_label/test/tf_100_codes.txt --input_mode $INPUT_MODE --label_type $LABEL_TYPE --label_filepath /root/autodl-tmp/3-opt/0428_lucaprot/LucaProt/dataset/tf_predict/protein/multi_class/label.txt --output_dir ../models/$DATASET_NAME/$DATASET_TYPE/$TASK_TYPE/$MODEL_TYPE/$time_str --log_dir ../logs/$DATASET_NAME/$DATASET_TYPE/$TASK_TYPE/$MODEL_TYPE/$time_str --tb_log_dir ../tb-logs/$DATASET_NAME/$DATASET_TYPE/$TASK_TYPE/$MODEL_TYPE/$time_str --config_path ./0425_sefn_config.json --seq_vocab_path /root/autodl-tmp/1-data/lucatf_multi_label/test/subword_100.txt --seq_pooling_type $SEQ_POOLING_TYPE --embedding_pooling_type $embedding_pooling_type --do_train --do_eval --do_predict --evaluate_during_training --per_gpu_train_batch_size=16 --per_gpu_eval_batch_size=16 --gradient_accumulation_steps=1 --learning_rate=1e-4 --num_train_epochs=1 --logging_steps=1000 --save_steps=1000 --overwrite_output_dir --loss_type cce --max_metric_type $MAX_METRIC_TYPE --seq_max_length=$SEQ_MAX_LENGTH --embedding_max_length=$embedding_max_length --trunc_type=$TRUNCT_TYPE --no_token_type_embeddings --embedding_input_size $embedding_input_size --embedding_type $embedding_type --shuffle_queue_size 1000 --save_all
报错信息:
你复制下run.py,其他代码不需要更新了
谢谢老师的积极回复,目前使用小样本建模已经成功了,预测功能也正常,我再用大样本试试,再次感谢!
祝好!