コード例 #1
0
 def __init__(self):
     super(NetEqualCount, self).__init__()
     self.equalcount = P.EqualCount()
     x = Tensor(np.array([1, 20, 5]).astype(np.int32))
     y = Tensor(np.array([2, 20, 5]).astype(np.int32))
     self.x = Parameter(initializer(x, x.shape), name='x')
     self.y = Parameter(initializer(y, y.shape), name='y')
コード例 #2
0
def extract_logits_for_lambada(logits=None, label_ids=None, input_mask=None):
    # equalcount = P.EqualCount()
    all_one = Tensor(np.ones(gpt2_net_cfg.seq_length), mindspore.int32)
    no_mask_length = []
    for i in range(input_mask.shape[0]):
        input_mask_row = input_mask[i, ::]
        valid_length = int(P.EqualCount()(input_mask_row,
                                          all_one).asnumpy()[0])
        # print("valid_length type is {}, length is {}".format(type(valid_length), valid_length)) # count the no padding token number
        no_mask_length.append(valid_length)

        logit = logits[i:i + 1:1, valid_length - 3:valid_length - 2:1, ::]
        label = label_ids[i:i + 1:1, valid_length - 2:valid_length - 1:1]
        # print("extract_logits logit shape: {}".format(logit.shape))
        if i == 0:
            output_logits = logit
            final_label_ids = label
        else:
            output_logits = P.Concat()((output_logits, logit))
            final_label_ids = P.Concat()((final_label_ids, label))

    print("output_logits shape : {}".format(output_logits.shape))
    print("output logits:\n{}".format(output_logits[:3, :, 7:15]))
    # print("final_label_ids shape : {}".format(final_label_ids.shape))
    # print("output final_label_ids:\n{}".format(final_label_ids))

    return output_logits, final_label_ids, no_mask_length
コード例 #3
0
        'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
        'skip': ['backward']}),
    # type of x and y not match
    ('Equal1', {
        'block': (P.Equal(), {'exception': TypeError, 'error_keywords': ['Equal']}),
        'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
        'skip': ['backward']}),
    # shape of x and y not match
    ('Equal2', {
        'block': (P.Equal(), {'exception': ValueError, 'error_keywords': ['Equal']}),
        'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32)), Tensor(np.ones([3, 2]).astype(np.float32))],
        'skip': ['backward']}),

    # input is not tensor
    ('EqualCount0', {
        'block': (P.EqualCount(), {'exception': TypeError, 'error_keywords': ['EqualCount']}),
        'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
        'skip': ['backward']}),
    # type of x and y not match
    ('EqualCount1', {
        'block': (P.EqualCount(), {'exception': TypeError, 'error_keywords': ['EqualCount']}),
        'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32)), Tensor(np.ones([3, 4]).astype(np.float32))],
        'skip': ['backward']}),
    # shape of x and y not match

    # input is not tensor
    ('NotEqual0', {
        'block': (P.NotEqual(), {'exception': TypeError, 'error_keywords': ['NotEqual']}),
        'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
        'skip': ['backward']}),
    # type of x and y not match
コード例 #4
0
 def __init__(self):
     super(NetEqualCount, self).__init__()
     self.equalcount = P.EqualCount()
コード例 #5
0
    # shape of x and y not match
    ('Equal2', {
        'block': (P.Equal(), {
            'exception': ValueError,
            'error_keywords': ['Equal']
        }),
        'desc_inputs': [
            Tensor(np.ones([3, 4]).astype(np.float32)),
            Tensor(np.ones([3, 2]).astype(np.float32))
        ],
        'skip': ['backward']
    }),

    # input is not tensor
    ('EqualCount0', {
        'block': (P.EqualCount(), {
            'exception': TypeError,
            'error_keywords': ['EqualCount']
        }),
        'desc_inputs': [5.0, Tensor(np.ones([3, 4]).astype(np.float32))],
        'skip': ['backward']
    }),
    # type of x and y not match
    ('EqualCount1', {
        'block': (P.EqualCount(), {
            'exception': TypeError,
            'error_keywords': ['EqualCount']
        }),
        'desc_inputs': [
            Tensor(np.ones([3, 4]).astype(np.int32)),
            Tensor(np.ones([3, 4]).astype(np.float32))