mirror of
https://github.com/explosion/spaCy.git
synced 2025-07-18 20:22:25 +03:00
Use scatter_add to speed up span embed backprop
This was the slowest part of the code, and using scatter_add here probably reduces the runtime by 50%.
This commit is contained in:
parent
d0b041aff4
commit
f34915c1e8
|
@ -187,14 +187,10 @@ def span_embeddings_forward(
|
|||
|
||||
out = model.ops.alloc2f(len(indoc), dim)
|
||||
|
||||
for ii, (start, end) in enumerate(dY.indices[offset:hi]):
|
||||
# adjust indexes to align with doc
|
||||
start -= tokoffset
|
||||
end -= tokoffset
|
||||
|
||||
out[start] += starts[ii]
|
||||
out[end] += ends[ii]
|
||||
out[start:end] += spanvecs[ii]
|
||||
idxs = dY.indices[offset:hi] - tokoffset
|
||||
ops.scatter_add(out, idxs[:, 0], starts)
|
||||
ops.scatter_add(out, idxs[:, 1], ends)
|
||||
ops.scatter_add(out, idxs.T, spanvecs)
|
||||
oweights.append(out)
|
||||
|
||||
offset = hi
|
||||
|
|
Loading…
Reference in New Issue
Block a user