Python wrapper for damo, a set of fast and robust hash functions.
Project description
Damo-Embedding
Quick Install
pip install damo-embedding
Example
DeepFM
import torch
import torch.nn as nn
from damo_embedding import Embedding
class DeepFM(torch.nn.Module):
def __init__(
self,
emb_size: int,
fea_size: int,
hid_dims=[256, 128],
num_classes=1,
dropout=[0.2, 0.2],
**kwargs,
):
super(DeepFM, self).__init__()
self.emb_size = emb_size
self.fea_size = fea_size
initializer = {
"name": "truncate_normal",
"mean": float(kwargs.get("mean", 0.0)),
"stddev": float(kwargs.get("stddev", 0.0001)),
}
optimizer = {
"name": "adam",
"gamma": float(kwargs.get("gamma", 0.001)),
"beta1": float(kwargs.get("beta1", 0.9)),
"beta2": float(kwargs.get("beta2", 0.999)),
"lambda": float(kwargs.get("lambda", 0.0)),
"epsilon": float(kwargs.get("epsilon", 1e-8)),
}
self.w = Embedding(
1,
initializer=initializer,
optimizer=optimizer,
**kwargs,
)
self.v = Embedding(
self.emb_size,
initializer=initializer,
optimizer=optimizer,
**kwargs,
)
self.w0 = torch.zeros(1, dtype=torch.float32, requires_grad=True)
self.dims = [fea_size * emb_size] + hid_dims
self.layers = nn.ModuleList()
for i in range(1, len(self.dims)):
self.layers.append(nn.Linear(self.dims[i - 1], self.dims[i]))
self.layers.append(nn.BatchNorm1d(self.dims[i]))
self.layers.append(nn.BatchNorm1d(self.dims[i]))
self.layers.append(nn.ReLU())
self.layers.append(nn.Dropout(dropout[i - 1]))
self.layers.append(nn.Linear(self.dims[-1], num_classes))
self.sigmoid = nn.Sigmoid()
def forward(self, input: torch.Tensor) -> torch.Tensor:
"""forward
Args:
input (torch.Tensor): input tensor
Returns:
tensor.Tensor: deepfm forward values
"""
assert input.shape[1] == self.fea_size
w = self.w.forward(input)
v = self.v.forward(input)
square_of_sum = torch.pow(torch.sum(v, dim=1), 2)
sum_of_square = torch.sum(v * v, dim=1)
fm_out = (
torch.sum((square_of_sum - sum_of_square)
* 0.5, dim=1, keepdim=True)
+ torch.sum(w, dim=1)
+ self.w0
)
dnn_out = torch.flatten(v, 1)
for layer in self.layers:
dnn_out = layer(dnn_out)
out = fm_out + dnn_out
out = self.sigmoid(out)
return out
Save Model
from damo_embedding import save_model
model = DeepFM(8, 39)
save_model(model, "./")
Document
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
damo-embedding-1.1.2.tar.gz
(45.1 kB
view hashes)
Built Distributions
Close
Hashes for damo_embedding-1.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ec841d90bf1ef9793960b66f846efab46ad4f6eb9d31e593292e9da7a40a960 |
|
MD5 | 75f60e35fd18144ff38d403d4a9b9787 |
|
BLAKE2b-256 | 8e327210cc3704f8d2ed2dcdb327c3b38610124493d0820e11c9dc8e0fea592b |
Close
Hashes for damo_embedding-1.1.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35adb98f1739338649099c02abefe7554d809e16dc7f6f1b23c2fbc0534bfd48 |
|
MD5 | 7383f5e4260d98dd3de662559bc32c58 |
|
BLAKE2b-256 | 06f83c2ad09c94244ecb8394128cb780df73221a814fb9b23d105d600a16136c |
Close
Hashes for damo_embedding-1.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 373d3ae743bc17f30848dcf0596688d8423eb617250eb9eba3203b9553a22ce2 |
|
MD5 | 5c3ea10f6f97ba46974ebfdf44afd7cc |
|
BLAKE2b-256 | d25acbf014b20ad7b733403faa3faff42448dbab392421d750f43f39e57f8c22 |
Close
Hashes for damo_embedding-1.1.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ebb0cfd60ad48873db90dbf33aff85524272f3e9a6fbc4f3a09cb35f50348f6 |
|
MD5 | 14eee713dbfe7d1667577e3c04069102 |
|
BLAKE2b-256 | f0952b1f0615483e7f843e7f4c2436bb22b2c29cb53f8c2491edb42bc4a349e8 |
Close
Hashes for damo_embedding-1.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d22aff0a9e759bfe27868b32c6a780618187e0ace452a068cf14ad00690eac06 |
|
MD5 | a7a0b1b4cd6b335bb0c479941a0c0175 |
|
BLAKE2b-256 | d51b14df0e8a930c78e1f54db2a4dcad2123b2549e4b88ccee7e04594103833e |
Close
Hashes for damo_embedding-1.1.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 026d9afee0f3dfbd9b6b867f4dd07f67951d84f73b1aa73f6ebebd272c466a94 |
|
MD5 | 2987c4b2497590cf5ae32e5e32592b57 |
|
BLAKE2b-256 | 68e59901843e4b88fd9f3724364f60d168dee0987c4c31c41fbb241eed29e6b4 |
Close
Hashes for damo_embedding-1.1.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 659daee262cfe231489440c7d544ed305e6ad548a0401005b36790ffbb5b4db2 |
|
MD5 | ac0fa9732fbc95f6ee46a3e93b494b08 |
|
BLAKE2b-256 | 6d978807926d46199ffe53230a371fa4edff785c25f4b89b50da14464d48df9c |
Close
Hashes for damo_embedding-1.1.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0873919c0a993774efc3e011f6cd0f9e6774b56ab549101dfb2fa8a39a49c8c5 |
|
MD5 | 1ebe25f066ad400aa071013538d3984b |
|
BLAKE2b-256 | 44330bed44c653d4a24841c9aab0b7db955f6d034a53c3b055735fec24dd0316 |
Close
Hashes for damo_embedding-1.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 869dd3005a0a8c42ffeb93a19e0e61dcdbb2e4ca81971f9f1f6f0060bab3bbfa |
|
MD5 | c745e669b9887d1985ad7f76b5df508c |
|
BLAKE2b-256 | 149701da8ece0bd072a132c2f5ccb5d8a26c22858032576847b4c43c23585dcd |
Close
Hashes for damo_embedding-1.1.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8df362e3b401707096d6052717e811c28dfa6de8839c42a3009b6919f628f5c8 |
|
MD5 | 2ece7659e9613f6b6fe9f78c70de841d |
|
BLAKE2b-256 | 4cad385ae959397d39e7615dda287bb434766e8d06920f536547b2cd3b89ffad |
Close
Hashes for damo_embedding-1.1.2-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b59fd6487b996b4e6a984863d60acafaf04061e8e385cc72de200dc117d9d6e5 |
|
MD5 | 7a1dbd550d591ef366d64bbed0eb94d1 |
|
BLAKE2b-256 | bf36e944399ad2a9981c5d46efea312c75168af16f8f83db9277d0f5291d4f28 |
Close
Hashes for damo_embedding-1.1.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58648ba802f2118b7b41ec21b844f0408fefccadc15460ca71c201427b0c3390 |
|
MD5 | 2b948c0b393378a2a66cdb8446ae1d47 |
|
BLAKE2b-256 | 0346f833f74eb2a22ced5c3752221d90afe0c0683adc73ba16d0b73b0137bb1a |
Close
Hashes for damo_embedding-1.1.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe4fb979d3ec1d6546d7b4601d050dab4a478e0e21783be82d63e71e62d05db8 |
|
MD5 | 73bca4d5e80c2932ac95753f2b22f634 |
|
BLAKE2b-256 | d82fed6c8526f7d12a13a22bf10d1b5e7f6bba149cefa3f7c36253c6a41dedab |
Close
Hashes for damo_embedding-1.1.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 183c067a6689bd73fd33ffc4e944825c875c1897a35c7c0599aa9ed1077dc837 |
|
MD5 | e5d034a6e0ffae8949e168bdfca0e7b8 |
|
BLAKE2b-256 | 166b8ff2b4c249c55c053bb27d32520dc16abeaf9ffaa9ea99f6cd16dec4d6a2 |
Close
Hashes for damo_embedding-1.1.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d653c6d37faf0dac1b08c0f8f75102e055a06c69bd7d4adaa76e1494b01702a1 |
|
MD5 | 1816e8ce4ea7d568c35e1893613cbb4e |
|
BLAKE2b-256 | 24e80e68bc0c7199ec12368cfe011cac6d345e902f330ee14493eb8ada53f9f5 |
Close
Hashes for damo_embedding-1.1.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df1cb9bf18d3ff1a189f67b21b388c5b3512dc6caa9e0ae0bb53f0fdfe4564c4 |
|
MD5 | 044159e894028dd165fad86d84812f0a |
|
BLAKE2b-256 | be184d7f7adff11bf94be4ace90508a314330d9741d30f4317c9a2fc664464ff |
Close
Hashes for damo_embedding-1.1.2-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e47bf9b46c48bd09d3405fd3ed13a286753b10feb66eb7846c0a2338b5847112 |
|
MD5 | 8349cd737a8e0ce13a2f9527b9c21e5b |
|
BLAKE2b-256 | 6be785e8582105ace4020330fdfb4b8a9ae50f7437ea0a7e5aad1cf9e0dd8073 |
Close
Hashes for damo_embedding-1.1.2-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd888d0150adfde7bd931035f828ff1366dfceb34132be8c8d2d9a196c27f609 |
|
MD5 | 91467ec34996645f91e66a5df809aa6d |
|
BLAKE2b-256 | 8a7a50c041d0c84031b481a45b6c3664d5666dba50d6489b8bb9db37ce0161e6 |