/
usr
/
local
/
lib64
/
python3.6
/
site-packages
/
caffe2
/
python
/
layers
/
/usr/local/lib64/python3.6/site-packages/caffe2/python/layers
mkdir
upload
Name
Size
Mode
Actions
__pycache__/
-
0755
rm
adaptive_weight.py
5687
0644
edit
dl
rm
add_bias.py
1396
0644
edit
dl
rm
arc_cosine_feature_map.py
7345
0644
edit
dl
rm
batch_huber_loss.py
3523
0644
edit
dl
rm
batch_lr_loss.py
11577
0644
edit
dl
rm
batch_mse_loss.py
2333
0644
edit
dl
rm
batch_normalization.py
3823
0644
edit
dl
rm
batch_sigmoid_cross_entropy_loss.py
1483
0644
edit
dl
rm
batch_softmax_loss.py
4580
0644
edit
dl
rm
blob_weighted_sum.py
2219
0644
edit
dl
rm
bpr_loss.py
1499
0644
edit
dl
rm
bucket_weighted.py
2355
0644
edit
dl
rm
build_index.py
1937
0644
edit
dl
rm
concat.py
4849
0644
edit
dl
rm
constant_weight.py
1208
0644
edit
dl
rm
conv.py
5050
0644
edit
dl
rm
dropout.py
1410
0644
edit
dl
rm
fc.py
9296
0644
edit
dl
rm
fc_without_bias.py
1954
0644
edit
dl
rm
fc_with_bootstrap.py
12788
0644
edit
dl
rm
feature_sparse_to_dense.py
14361
0644
edit
dl
rm
functional.py
4875
0644
edit
dl
rm
gather_record.py
3260
0644
edit
dl
rm
homotopy_weight.py
4306
0644
edit
dl
rm
label_smooth.py
3507
0644
edit
dl
rm
last_n_window_collector.py
2392
0644
edit
dl
rm
layers.py
17412
0644
edit
dl
rm
layer_normalization.py
4291
0644
edit
dl
rm
margin_rank_loss.py
1951
0644
edit
dl
rm
merge_id_lists.py
1500
0644
edit
dl
rm
pairwise_similarity.py
3549
0644
edit
dl
rm
position_weighted.py
2066
0644
edit
dl
rm
random_fourier_features.py
3187
0644
edit
dl
rm
reservoir_sampling.py
3013
0644
edit
dl
rm
sampling_train.py
2210
0644
edit
dl
rm
sampling_trainable_mixin.py
1366
0644
edit
dl
rm
select_record_by_context.py
2381
0644
edit
dl
rm
semi_random_features.py
5809
0644
edit
dl
rm
sparse_dropout_with_replacement.py
3943
0644
edit
dl
rm
sparse_feature_hash.py
4618
0644
edit
dl
rm
sparse_itemwise_dropout_with_replacement.py
3944
0644
edit
dl
rm
sparse_lookup.py
22170
0644
edit
dl
rm
split.py
2257
0644
edit
dl
rm
tags.py
4114
0644
edit
dl
rm
uniform_sampling.py
2779
0644
edit
dl
rm
__init__.py
943
0644
edit
dl
rm
Edit:
/usr/local/lib64/python3.6/site-packages/caffe2/python/layers/pairwise_similarity.py
(3549B)
## @package dot_product # Module caffe2.python.layers.dot_product from caffe2.python import schema from caffe2.python.layers.layers import ( ModelLayer, ) class PairwiseSimilarity(ModelLayer): def __init__(self, model, input_record, output_dim, pairwise_similarity_func='dot', name='pairwise_similarity', **kwargs): super(PairwiseSimilarity, self).__init__(model, name, input_record, **kwargs) assert isinstance(input_record, schema.Struct), ( "Incorrect input type. Expected Struct, but received: {0}". format(input_record)) assert ( ('all_embeddings' in input_record) ^ ('x_embeddings' in input_record and 'y_embeddings' in input_record) ), ( "either (all_embeddings) xor (x_embeddings and y_embeddings) " + "should be given." ) self.pairwise_similarity_func = pairwise_similarity_func if 'all_embeddings' in input_record: x_embeddings = input_record['all_embeddings'] y_embeddings = input_record['all_embeddings'] else: x_embeddings = input_record['x_embeddings'] y_embeddings = input_record['y_embeddings'] assert isinstance(x_embeddings, schema.Scalar), ( "Incorrect input type for x. Expected Scalar, " + "but received: {0}".format(x_embeddings)) assert isinstance(y_embeddings, schema.Scalar), ( "Incorrect input type for y. Expected Scalar, " + "but received: {0}".format(y_embeddings) ) if 'indices_to_gather' in input_record: indices_to_gather = input_record['indices_to_gather'] assert isinstance(indices_to_gather, schema.Scalar), ( "Incorrect type of indices_to_gather. " "Expected Scalar, but received: {0}".format(indices_to_gather) ) self.indices_to_gather = indices_to_gather else: self.indices_to_gather = None self.x_embeddings = x_embeddings self.y_embeddings = y_embeddings dtype = x_embeddings.field_types()[0].base self.output_schema = schema.Scalar( (dtype, (output_dim,)), self.get_next_blob_reference('output') ) def add_ops(self, net): if self.pairwise_similarity_func == "cosine_similarity": x_embeddings_norm = net.Normalize(self.x_embeddings(), axis=1) y_embeddings_norm = net.Normalize(self.y_embeddings(), axis=1) Y = net.BatchMatMul( [x_embeddings_norm, y_embeddings_norm], [self.get_next_blob_reference(x_embeddings_norm + '_matmul')], trans_b=1, ) elif self.pairwise_similarity_func == "dot": Y = net.BatchMatMul( [self.x_embeddings(), self.y_embeddings()], [self.get_next_blob_reference(self.x_embeddings() + '_matmul')], trans_b=1, ) else: raise NotImplementedError( "pairwise_similarity_func={} is not valid".format( self.pairwise_similarity_func ) ) if self.indices_to_gather: flattened = net.Flatten( Y, Y + '_flatten', ) net.BatchGather( [flattened, self.indices_to_gather()], self.output_schema(), ) else: net.Flatten(Y, self.output_schema())
Save
cmd:
run