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.1.tar.gz
(44.3 kB
view hashes)
Built Distributions
Close
Hashes for damo_embedding-1.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cace2edbc2f94bc28415d5fbd11c5c5d170c3a0317d370629f3fe20d911fb300 |
|
MD5 | b99228507e2505bfc8c5019a63fb3df4 |
|
BLAKE2b-256 | f14b652c3b378d3e1c0522f34787c9bcbf3f27185adeef3e5360193ca3f740a5 |
Close
Hashes for damo_embedding-1.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0088e6f5d226758618c68d05fa455bdc7cdc7a056f628a6bda4df2bfccc2a737 |
|
MD5 | e0b28a453461db9058c83bc18e8e7b68 |
|
BLAKE2b-256 | 87b54dbd2e2a3660150354118204c80879b0f346c3b41f7bbb73a8415484c907 |
Close
Hashes for damo_embedding-1.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4c751887ea0fdb95ae9ff9b7a3666558dfe8da1ee56aa57233ce544125d0cad |
|
MD5 | b65656622f955bef30adcefbd795266f |
|
BLAKE2b-256 | 3c0efe26db1b66c2613a5abccd6f9278759c3c4c013eb82089c029fed27defea |
Close
Hashes for damo_embedding-1.1.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3356ddb15e128f463a3440337675dc1c3bd434605255741bee33e2f6a70778e7 |
|
MD5 | 77bcb66c06cfa7cdd09df018271cc75e |
|
BLAKE2b-256 | 74a061e9664a927dd6e3799742e710a73a526bd30ae0541fabfdc4324ffed4e2 |
Close
Hashes for damo_embedding-1.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e587e56b7b70c75865fde152a03f39aaccb7e4b5caffe47f5a9aad1a94af55cd |
|
MD5 | 0f9a9da0ee1ba2c9683dcf227a63a248 |
|
BLAKE2b-256 | 20e6a325325564e22500d812703777a396ec4597aee8cb9e3259cfb9f73619cf |
Close
Hashes for damo_embedding-1.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6c9ac5a0585996fd70d3de9f5b2fe8c6589421318a713098c209a56527af107 |
|
MD5 | 80309a41642ce81577b546a92ea4d876 |
|
BLAKE2b-256 | ebe994c2d68ddf1235cb7715fabca6c2e8416e51fe3a2bdb48d4406ceeea313b |
Close
Hashes for damo_embedding-1.1.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87ef7c0652d98c21eedbd830cb8a8a28b6811115182e801e44dd74de643ccc91 |
|
MD5 | fd7ff7156335d653b8fbd3766e94af36 |
|
BLAKE2b-256 | 4f4a913bd8b40666d7d02a9bce2f7feb815aa4dfaa6daa1a9058f1cf4dbc28ed |
Close
Hashes for damo_embedding-1.1.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | acb59fdcac0b177caf641c7760f6a56bed07467ab684c86d00878f6352ad760e |
|
MD5 | 5c192d94a8f6cbf25f954e4e228fc50d |
|
BLAKE2b-256 | 05e642419a1bb7ac0ba0e74e1d92455266ba73cc2ee9e7ebafeca7d14cf28958 |
Close
Hashes for damo_embedding-1.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb54217da9476f4ff7b577f04d08671c671ce632d77f541d5b0f41e192675c07 |
|
MD5 | 2db646fbf5809e136cf15c91d18cfd69 |
|
BLAKE2b-256 | 34990a9b3801021a133488ed7bde7e14822c7167672e406ed6f1248633827a47 |
Close
Hashes for damo_embedding-1.1.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65b77d259b5071a03d91fb073067b562d652f403f5bf0b3c0718bfa6cbc6f029 |
|
MD5 | 9ba01dd57d7d1a257b3b16c9e4585fb7 |
|
BLAKE2b-256 | a200bd6224f07cceccbc1c539a4d27683ae6c752836e2aa200c1f6d104fb01b5 |
Close
Hashes for damo_embedding-1.1.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9856b11848df15860e0d5d07386e74a17c5e91009f8315a8d2d3bc66f104f7bd |
|
MD5 | fb85fa2ce76ed913fb8faa57f7382aa9 |
|
BLAKE2b-256 | 7a89b189fe6295c753f0ae4c27fe2b0637e95cc0f8ff470b23c2564d95da761e |
Close
Hashes for damo_embedding-1.1.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e432964cbc9690aec2e665be329498c367afe4d11808441ba2ba16b683300594 |
|
MD5 | 6f3ace59f9fae45289a461ea4a44e0e2 |
|
BLAKE2b-256 | d8a48ebee689cb07ff98ea068fcbad20e052e68a7bc17b34c679e842efe3cab4 |
Close
Hashes for damo_embedding-1.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6f20a76f302adeb308149723d027d74d73649680ee23457cdc109027c03d8b1 |
|
MD5 | d3edfdc9a3351061a9c50c82a840c6c0 |
|
BLAKE2b-256 | 1fb9659da388ac84af00cf45e1d2b6d4a1f2e5f9a796c7717e2691a3ccd2cb61 |
Close
Hashes for damo_embedding-1.1.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | affef6136cc0762dc0ffc396de7e3cd3fe33d6a219e8f521b769904ce8044efa |
|
MD5 | 4a90b2b94f018e52ae757fbf5741edc0 |
|
BLAKE2b-256 | 43fcc517a30f12d324fcce73e058f2b4cb9b681626033bc2fb939f4d62e1abe9 |
Close
Hashes for damo_embedding-1.1.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bbc0ccf0b395d2c173b0efee9ad29d0ad00e0a309b13759269793bf9de02121 |
|
MD5 | 637c8ed1e7dff0715ad462afc3ab2fee |
|
BLAKE2b-256 | ef5e4aa0b268166f1d995737b6c62801ec86e37237b5bcfa56c424f008d432cd |
Close
Hashes for damo_embedding-1.1.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44d40aaa706767fbd225ff5667cb7a0fcc4cbb5e526a1df9abdc05748f299dec |
|
MD5 | eca9b295665a18b659952158beafac67 |
|
BLAKE2b-256 | 5021b9849ac3c545877591d01014d1094b32bde3f361e47e726615aacbdd16a3 |
Close
Hashes for damo_embedding-1.1.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7f2c5b56bd1d55e9780218d1ca1d97ea70dc0c13b4ce40f8264e1ad77589010 |
|
MD5 | 38788bfb4b80100136b0403a501a9ead |
|
BLAKE2b-256 | 375fa1ace8070d546ccce0a04cfa5c0e37438879b38d4e00b8fab83eee9f5ad3 |
Close
Hashes for damo_embedding-1.1.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07abb9aeaee7a3108f8e28e0e96a442908aace8ad7ce9d70514e909107d39df9 |
|
MD5 | bc689c30daf50fca1cefdd34e70adec5 |
|
BLAKE2b-256 | b7b1855df90e5abae0564a003e053e2639b1dedb1522c26ce6992999cf349481 |