You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am a student studying GNN and recently I have been working on a project using AMR graphs.
I came across an issue while trying to use the AMR graph library in the code uploaded to a repository.
And I tried fixing it myself, but I'd like some feedback to ensure that the changes I made are correct.
Finally, I found an error that global variables are not shared when using multiprocessing.
So, I used functools.partial to pass arguments to the worker function and resolved the issue.
I'm not sure if the uploaded code was originally correct.
Below is the code that I modified.
Could you please confirm if the code below is correct? Thank you!
importreimportloggingfrommultiprocessingimportPoolfromtqdmimporttqdmimportnumpyfromfunctoolsimportpartialgfeaturizer, gmax_dist=None, None# for multiprocessingdefbuild_coref_features(mdata, model, **kwargs):
chunksize=kwargs.get('feat_chunksize', 200)
maxtpc=kwargs.get('feat_maxtasksperchild', 200)
processes=kwargs.get('feat_processes', None) # None = use os.cpu_count()show_prog=kwargs.get('show_prog', True)
globalgfeaturizer, gmax_distgfeaturizer=CorefFeaturizer(mdata, model)
gmax_dist=model.config.max_distifmodel.config.max_distisnotNoneelse999999999# Build the list of doc_names and mention indexes for multiprocessing and the output containeridx_keys= [(dn, idx) fordn, mlistingfeaturizer.mdata.mentions.items() foridxinrange(len(mlist))]
feat_data= {}
fordn, mlistingfeaturizer.mdata.mentions.items():
feat_data[dn] = [None]*len(mlist)
# Loop through and get the pair features for all antecedentspbar=tqdm(total=len(idx_keys), ncols=100, disable=notshow_prog)
withPool(processes=processes, maxtasksperchild=maxtpc) aspool:
worker_with_args=partial(worker, gfeaturizer=gfeaturizer, gmax_dist=gmax_dist)
forfdatainpool.imap_unordered(worker_with_args, idx_keys, chunksize=chunksize):
dn, midx, sspans, dspans, words, sfeats, pfeats, slabels, plabels=fdatafeat_data[dn][midx] = {'sspans':sspans, 'dspans':dspans, 'words':words,
'sfeats':sfeats, 'pfeats':pfeats,
'slabels':slabels, 'plabels':plabels}
pbar.update(1)
pbar.close()
# Error checkfordn, feat_listinfeat_data.items():
assertNonenotinfeat_listreturnfeat_datadefworker(idx_key, gfeaturizer, gmax_dist):
globalgfrozen_embedsdoc_name, midx=idx_keymlist=gfeaturizer.mdata.mentions[doc_name]
mention=mlist[midx] # the head mentionantecedents=mlist[:midx] # all antecedents up to (not including) head mentionantecedents=antecedents[-gmax_dist:] # truncate earlier value so list is only max_dist long# Process the single and pair data datasspan_vector=gfeaturizer.get_sentence_span_vector(mention)
dspan_vector=gfeaturizer.get_document_span_vector(mention)
word_indexes=gfeaturizer.get_word_indexes(mention)
sfeats=gfeaturizer.get_single_features(mention)
pfeats=gfeaturizer.get_pair_features(mention, antecedents)
# Build target labels. Note that if there are no clusters in the mention data this will still# return a list of targets, though all singles will be 1 and pairs 0slabels, plabels=gfeaturizer.build_targets(mention, antecedents)
returndoc_name, midx, sspan_vector, dspan_vector, word_indexes, sfeats, pfeats, slabels, plabels
The text was updated successfully, but these errors were encountered:
Hello,
I am a student studying GNN and recently I have been working on a project using AMR graphs.
I came across an issue while trying to use the AMR graph library in the code uploaded to a repository.
And I tried fixing it myself, but I'd like some feedback to ensure that the changes I made are correct.
Finally, I found an error that global variables are not shared when using multiprocessing.
So, I used functools.partial to pass arguments to the worker function and resolved the issue.
I'm not sure if the uploaded code was originally correct.
Below is the code that I modified.
Could you please confirm if the code below is correct? Thank you!
The text was updated successfully, but these errors were encountered: