Skip to content

Commit

Permalink
[tokenizers] Make encoding types to int
Browse files Browse the repository at this point in the history
  • Loading branch information
xyang16 committed Sep 12, 2024
1 parent 8247e57 commit 2c14fde
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import ai.djl.ndarray.NDList;
import ai.djl.ndarray.NDManager;

import java.util.Arrays;

/** A class holds token encoding information. */
public class Encoding {

Expand Down Expand Up @@ -59,10 +61,13 @@ protected Encoding(
*/
public NDList toNDList(NDManager manager, boolean withTokenType) {
NDList list = new NDList(withTokenType ? 3 : 2);
list.add(manager.create(ids));
list.add(manager.create(attentionMask));
int[] ids2 = Arrays.stream(ids).mapToInt(i -> (int) i).toArray();
int[] attentionMask2 = Arrays.stream(attentionMask).mapToInt(i -> (int) i).toArray();
list.add(manager.create(ids2));
list.add(manager.create(attentionMask2));
if (withTokenType) {
list.add(manager.create(typeIds));
int[] typeIds2 = Arrays.stream(typeIds).mapToInt(i -> (int) i).toArray();
list.add(manager.create(typeIds2));
}
return list;
}
Expand Down

0 comments on commit 2c14fde

Please sign in to comment.