You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python初学者求助:特征提取作业第二部分完成方法

CoNLL-U数据处理作业:特征提取部分求助

我正在完成作业,但已卡壳数周,完全不清楚特征提取部分该如何操作。我附上了两张截图:

  • 第一张截图
  • 第二张截图

第一部分我已完成,代码如下:

import conllu
from conllu import parse

def read_conllu(filename):
    words_frGSD =[]
    upos_frGSD = []
    sentence_length = []
    index_new = 0 
    final_list = []
    with open(filename,'r') as fr_GSD:
        frGSDPar = parse(fr_GSD.read())
        #get the lenght of every sentence 
        for i in range(len(frGSDPar)):
            sentence_length.append(len(frGSDPar[i]))
        ## extract words 
        for word in frGSDPar:
            for i in range(len(word)):
                words_frGSD.append(word[i]['form'])
                upos_frGSD.append(word[i]['upos'])
        ## following the length to get the pair 
        for i in range(len(sentence_length)):
            word = []
            label = []
            lst1 = [] 
            sentence_length_total = sentence_length[i]
            word = words_frGSD[index_new:(index_new+sentence_length_total)]
            label = upos_frGSD[index_new:(index_new+sentence_length_total)]
            lst1.append(word)
            lst1.append(label)
            final_list.append(lst1)
            index_new = index_new + sentence_length_total

    return final_list,words_frGSD,upos_frGSD

我是Python初学者,代码略显冗余,但第一部分已完成,不知如何进行第二部分。


内容的提问来源于stack exchange,提问作者SidneyNLPStruggling

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 17:30:43