问题描述
抱歉有任何混淆!!这是一个编辑过的版本——我试图让它的重现性最低。
# embed subject recall in vector space
def run_sts_benchmark(batch):
sts_encode1 = tf.nn.l2_normalize(embed(tf.constant(batch['sent_1'].tolist())),axis=1)
sts_encode2 = tf.nn.l2_normalize(embed(tf.constant(batch['sent_2'].tolist())),axis=1)
cosine_similarities = tf.reduce_sum(tf.multiply(sts_encode1,sts_encode2),axis=1)
clip_cosine_similarities = tf.clip_by_value(cosine_similarities,-1.0,1.0)
scores = 1.0 - tf.acos(clip_cosine_similarities) / math.pi
return scores
sub = "5ae5e66d3ab2fb0001ef2f3c"
item = "Armor"
df = pd.DataFrame()
# open file that is in a folder called "Armor" && named after subject ID
with open("....directory..../Armor/5ae5e66d3ab2fb0001ef2f3c.csv") as f2:
next(f2)
resp = csv.reader(f2)
resp_list = []
for row in resp:
sent_1 = []
sent = row[0]
sent_1.append(sent)
resp_list.append(sent)
# open answer sheet
with open("....directory..../answer_sheets/Armor.csv") as f:
score_key = csv.reader(f)
for row in score_key:
sent_2 = row
# make file col1:subject response,col2: correct answer
data = pd.DataFrame({"sent_1":sent_1,"sent_2":sent_2})
# score semantic similarity between response && answer
score = run_sts_benchmark(data).numpy()
# binarize semantic similarities
if score >= threshold:
acc = 1
else:
acc = 0
data['score'] = score
data['step_acc'] = acc
df = df.append(data)
# each clause of a subject recall is compared to every clause of an answer sheet and has a similarity score
df_acc = df.groupby('sent_1').sum()
错误——
Traceback (most recent call last):
File "<stdin>",line 1,in <module>
File "/opt/anaconda3/lib/python3.8/site-packages/pandas/core/frame.py",line 6511,in groupby
return DataFrameGroupBy(
File "/opt/anaconda3/lib/python3.8/site-packages/pandas/core/groupby/groupby.py",line 525,in __init__
grouper,exclusions,obj = get_grouper(
File "/opt/anaconda3/lib/python3.8/site-packages/pandas/core/groupby/grouper.py",line 781,in get_grouper
raise KeyError(gpr)
KeyError: 'sent_1'
在尝试运行最后一行时发生。我尝试在函数之外运行它,给受试者的回忆打分一行,但没有发生错误。有没有办法在迭代多次召回时避免这个错误?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)