crf java实现_Tensorflow实现crf损失
我試圖在Tensorflow圖中使用條件隨機場丟失 .
我正在執(zhí)行序列標(biāo)記任務(wù):
我有一系列元素作為輸入 [A, B, C, D] . 每個元素可以屬于3個不同類中的一個 . 類以單熱編碼方式表示:屬于類0的元素由向量[ 1, 0, 0] 表示 .
我的輸入標(biāo)簽(y)的大小( batch_size x sequence_length x num_classes ) .
我的網(wǎng)絡(luò)生成具有相同形狀的logits .
假設(shè)我的所有序列都有4個長度 .
這是我的代碼:
import tensorflow as tf
sequence_length = 4
num_classes = 3
input_y = tf.placeholder(tf.int32, shape=[None, sequence_length, num_classes])
logits = tf.placeholder(tf.float32, shape=[None, None, num_classes])
dense_y = tf.argmax(input_y, -1, output_type=tf.int32)
log_likelihood, _ = tf.contrib.crf.crf_log_likelihood(logits, dense_y, sequence_length)
我收到以下錯誤:
文件“”,第1行,在文件“/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/crf/python/ops/crf.py”,第182行,in crf_log_likelihood transition_params)文件“ /usr/local/lib/python2.7/dist-packages/tensorflow/contrib/crf/python/ops/crf.py“,第109行,in crf_sequence_score false_fn = _multi_seq_fn)文件”/ usr / local / lib / python2 . 7 / dist-packages / tensorflow / python / layers / utils.py“,第206行,在smart_cond pred中,true_fn = true_fn,false_fn = false_fn,name = name)文件”/usr/local/lib/python2.7/dist -packages / tensorflow / python / framework / smart_cond.py“,第59行,在smart_cond name = name中)文件”/usr/local/lib/python2.7/dist-packages/tensorflow/python/util/deprecation.py“ ,第432行,在new_func中返回func(* args,** kwargs)文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py”,第2063行,在cond orig_res_t中,res_t = context_t.BuildCondBranch(true_fn)文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py”,第1913行,BuildCondBra nch original_result = fn()文件“/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/crf/python/ops/crf.py”,第95行,在_single_seq_fn array_ops.concat中[(example_inds, tag_indices],axis = 1))文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py”,第2975行,在gather_nd“GatherNd”中,params = params,indices = indices,name = name)文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py”,第787行,在_apply_op_helper中op_def = op_def)文件“/ usr / local /lib/python2.7/dist-packages/tensorflow/python/framework/ops.py“,第3392行,在create_op中op_def = op_def)文件”/usr/local/lib/python2.7/dist-packages/tensorflow/ python / framework / ops.py“,第1734行,在init control_input_ops中)文件”/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py“,第1570行,在_create_c_op中ValueError(str(e))ValueError:indices.shape [-1]必須是<= params.rank,但看到索引形狀:[?,5]和params形狀:[?,3]為'cond / GatherNd '(op:'GatherNd')輸入形狀:[?,3],[?,5]
總結(jié)
以上是生活随笔為你收集整理的crf java实现_Tensorflow实现crf损失的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华人拍下大熊猫丫丫情况 网友:再这样下去
- 下一篇: 新疆球员艾菲尔丁,董路评价艾菲尔丁:行为