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.3.tar.gz
(45.1 kB
view hashes)
Built Distributions
Close
Hashes for damo_embedding-1.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cd47882f523bb14d090cd02c4e544bc8f30d973ab4512e35b8f2663f84c28f6 |
|
MD5 | 59a60b3e38f63e83af13f9f93491fbac |
|
BLAKE2b-256 | 222130238a7a76c0103e796efdea0bd6d03930cc8fe00f7e8907a4985f1b0e77 |
Close
Hashes for damo_embedding-1.1.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30d35c8421d11e3996216dedb2e2d2b1a694a14984effeb6d2ccb91022da1e86 |
|
MD5 | 1da95e74ea812bb11897323bb6fe136d |
|
BLAKE2b-256 | 46845b59f6b5bf6b3d1a4ca1553491d1fa0a9e619138494d223453890e0dd38c |
Close
Hashes for damo_embedding-1.1.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9323b04880f4a83f2d190e82e952259b4c106b6313a5a8204841262e5654ca82 |
|
MD5 | a59aaa39f77d4bcbbd3b9623708b0673 |
|
BLAKE2b-256 | faa028a7bb90793c77bdbcf1eb0cae7b716b1ce714f42fa081310770f3a76570 |
Close
Hashes for damo_embedding-1.1.3-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3c2c88ce5240edffd50d1717b9df3d9a232bc365a1b6d4daccd29461d8cf67d |
|
MD5 | 431c3b66346d80d50cd969a6fec696f8 |
|
BLAKE2b-256 | 0f39f87072531113d46e64675b73736bc534c5dfbda6820284677f146f342aa1 |
Close
Hashes for damo_embedding-1.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6c7621defb0a41963e379b29c40ac35dd1356f9b272536cbd222392f144b7e8 |
|
MD5 | 001eb1f036261958a453dbc7d738583e |
|
BLAKE2b-256 | d902a29dd0c30679e4d447770f456d3390c08f78a69029495a10d197f7c1c0a0 |
Close
Hashes for damo_embedding-1.1.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13a3f6050304d799adfcca6156a9b873cfbf0f1ef1dc1f1dc3a2acf87bf1e1a2 |
|
MD5 | 223da4afce410ed70a10a71cceeca160 |
|
BLAKE2b-256 | cee95ded19b982c52ba96977a374caeab7932625d0d8096da6a542e85ed6d414 |
Close
Hashes for damo_embedding-1.1.3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9da0a23b8f62762f583e6f98c5cb11079eb7496d919b19986fd1791cae9a757c |
|
MD5 | 8a9f9ab7ce43ef4aa596ad2741ed1467 |
|
BLAKE2b-256 | 8c2aa63f2194f05fda94d15665022fd85f0340cfe1e6dcd35d1d92b72735a028 |
Close
Hashes for damo_embedding-1.1.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 385945a3998efdbc93779129ebb90dab7ab472c2e7f816f23554945bed976c3c |
|
MD5 | 6b6dc4b43dd978cbd4af9f1785578fb4 |
|
BLAKE2b-256 | b4584dc74414b96ca115c5a1c3b298a510fab2e6d5e67f5e434c303f532372a0 |
Close
Hashes for damo_embedding-1.1.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c6bbdbccdb7ffb8c3424faef28934c0e91d377a1c10b8552886c2910b5985a8 |
|
MD5 | 9f1d759fe40caa5dcc405fbaf5cec457 |
|
BLAKE2b-256 | 708d32400e8e0d290aaee98356da05929a9ab37a073646917b528bc82a75a99a |
Close
Hashes for damo_embedding-1.1.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8b30c752af2d3cf77310942c0f8c1f05edecf533117814d40421cd5f11cb919 |
|
MD5 | 3c7c80d20bd122f35da0157a1f2af1f5 |
|
BLAKE2b-256 | 7fa615043a899e1b0084f3d524bfb38af636ef59c0bf866a2b2ed61d57b450b5 |
Close
Hashes for damo_embedding-1.1.3-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc7cd0d7f4cd4fe9847e498bea17e7df9e93fac10800c957099194b300e258d2 |
|
MD5 | 73d8c635a259e7f266799860d323c39b |
|
BLAKE2b-256 | 2501488a51a5a51b9922efbe9c33361dd73dab35ca7ba88ce463bb5f44e53f8f |
Close
Hashes for damo_embedding-1.1.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce1f61779977cfd537ca19b2916605d4ea3d7bbbaf8b03d6dc6c876569cd98b6 |
|
MD5 | 9010cdaee55421010997ec3c7d1461f6 |
|
BLAKE2b-256 | 8dc8218eb014cc5e45ac970465fd8fafca113d1e86a5cfb604f8ce8bbda527af |
Close
Hashes for damo_embedding-1.1.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa8775b8d06c3992189089faeb243c53dca40a2912a27fb69e1ece2fb89dd7a0 |
|
MD5 | faf1023ad4c191b553d5627515684399 |
|
BLAKE2b-256 | 3526c0c47542e1530e8e04008e2ac2780a39c790f13c633ad1bbd5b09250953a |
Close
Hashes for damo_embedding-1.1.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f08ddf8db3a195698a704657c7fcf6ed21201f57342f1746461c29432f61202a |
|
MD5 | 6e586ad447e9beb24994a9e6e62669ad |
|
BLAKE2b-256 | 6826132e808e597c8036ba9ec9585bf0f825397b3910e17e1932cc5ac4d2800c |
Close
Hashes for damo_embedding-1.1.3-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6aa2dca104b38c43685d644a8edef9a3bdf1d239a4d851a343ff315b6516322 |
|
MD5 | 630767940ee30fe6e4ae2a2d66073c17 |
|
BLAKE2b-256 | fadc6cadb7c4c3e2863319a1fc5642bad96d1b2da5ac81a56dafa639f816608c |
Close
Hashes for damo_embedding-1.1.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20301dc71500818c26ecfd82a71626b0abc8c6e9c12007c0e2b2408296f872e4 |
|
MD5 | fe6c13376822d809ce0007f0373a4f8d |
|
BLAKE2b-256 | 35497a72a06a065b18be2f0ff5d3c916206692216e7dbfb51baeb134e227963d |
Close
Hashes for damo_embedding-1.1.3-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c518fa4f4683a02c00ad1e57e6cda4a2560b1209442de2161408ffc5f30d30d4 |
|
MD5 | 1025e3f5b324041967f7edc5914091b1 |
|
BLAKE2b-256 | 48555dbe4b4b9bda48c830934d1eede32507879e67aefb0c7d8a09ab3c0cd29e |
Close
Hashes for damo_embedding-1.1.3-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d83863be314ae874178f24924ea2bdbba1e68b84d81a1b1a7fb29eebd97312c2 |
|
MD5 | 01d71c4204ac06e345e493b7c0a9a46e |
|
BLAKE2b-256 | e9e99c642a335f333a288572124087a44eaacae2a178a2e4164b6a94bc0129d3 |