一系列常用模型的Keras实现
Multilayer Perceptron (MLP) for multi-class softmax classification
from keras.models import Sequential
#!/usr/bin/env python3 | |
# Copyright (c) Facebook, Inc. and its affiliates. | |
# All rights reserved. | |
# | |
# This source code is licensed under the BSD-style license found in the | |
# LICENSE.txt file in the root directory of this source tree. | |
def get_torchbiggraph_config(): |
# coding=utf-8 | |
# Copyright 2018 The Google AI Language Team Authors and The HugginFace Inc. team. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software |
def cosine_distance(x1, x2=None, eps=1e-8): | |
x2 = x1 if x2 is None else x2 | |
w1 = x1.norm(p=2, dim=1, keepdim=True) | |
w2 = w1 if x2 is x1 else x2.norm(p=2, dim=1, keepdim=True) | |
return 1 - torch.mm(x1, x2.t()) / (w1 * w2.t()).clamp(min=eps) |