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,
)
self.v = Embedding(
self.emb_size,
initializer=initializer,
optimizer=optimizer,
)
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, "./", training=False)
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.11.tar.gz
(224.4 kB
view hashes)
Built Distributions
Close
Hashes for damo_embedding-1.1.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc0d49c3e1a59e679cdde2d67dd723ee2478f6eb85953abf3dd67490574e67e3 |
|
MD5 | fcc2fae52f0b93022c4a63a9b796958a |
|
BLAKE2b-256 | be98c4cfa1dfc4577ab0fae2d5a8494381126daed93c8e2d425598f530fca5cd |
Close
Hashes for damo_embedding-1.1.11-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5afb280b6127be922066e29be0093b90cc6153a254b8d33e9bec9668ef51c645 |
|
MD5 | bd94283b95e87a4f0fde22d04d986f47 |
|
BLAKE2b-256 | 98f5503dee6752963f4d84043b8d61e6e783677673d3b219254d5c6e086d3c20 |
Close
Hashes for damo_embedding-1.1.11-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c56988d6286b1d9d87a7dc77a0f8e64dbd3ca03fc7c7685e332eb9bee9e4560 |
|
MD5 | 75571630417f81adc2a86a4fe6e1f5cf |
|
BLAKE2b-256 | 1f17847271947b5409acec8f5711a02f8fc2da1f34de7d09726ab3564e750945 |
Close
Hashes for damo_embedding-1.1.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ef95a2f07f4062f1c7197edf578917affc0cbe912cc7c53a59188e91ee237cc |
|
MD5 | 0a7a0bd1cfe20492d481c7f58fb10b64 |
|
BLAKE2b-256 | 3f7caed8a8ea2c4a2343c88baf7e81b987e24c1133e561cd7c8354da05aea052 |
Close
Hashes for damo_embedding-1.1.11-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cff93696d036d6937b6ad3e7ac48d504e92c01eaf6603f8bb7fab639e47b35f3 |
|
MD5 | e98e2dceaf43966fe6f4b57668d3a4f6 |
|
BLAKE2b-256 | eb79252b2146509e3303d1646e615567ba3cdf800d978adb0584d621667a0ba7 |
Close
Hashes for damo_embedding-1.1.11-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf5341dcc956f36baa498a18db455664e5dab01bd90fe4e49c42f18241f5da37 |
|
MD5 | 22f648323ba0ad22a6213272b57b5918 |
|
BLAKE2b-256 | f6c1e5e6607f95957b759405ea1b62eedab21a9a1b371948973f743a041b40e5 |
Close
Hashes for damo_embedding-1.1.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63afb4cf1a69ede41dfe68f602282ceac3d35851c5e4fe31875995610f51031c |
|
MD5 | aa5f2fb66693dfbfcd4ba30279521f57 |
|
BLAKE2b-256 | 429d66e0bfd3cad4c4981c685de87724b45acac750c8eddb9922ee3d8bb41759 |
Close
Hashes for damo_embedding-1.1.11-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b068cfb35c1b42321ae4539927be76b13fd05905521a3ee6a229d8a38ad14bbc |
|
MD5 | d67466816a81176df6e769bc2cc21d19 |
|
BLAKE2b-256 | 7a757cafa9af9f24737224e8b767da927c9b16e55bbbbbe848bcc6d36690e34a |
Close
Hashes for damo_embedding-1.1.11-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de7001d0fe1ab7643cc2097bc4b465ff8959e8dda38b18cf8e79ea7a0c4ee91d |
|
MD5 | 3297e6a2f8010485db00fadda5466aaa |
|
BLAKE2b-256 | f1ca3c204a90bc962abd753d408660ebced0152afef68fbe88137a969a2cbd6d |
Close
Hashes for damo_embedding-1.1.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37d250245fc6f23ffda1a0cbbab30853010bde5a5dd1c5e8b365cbb6ab699e4e |
|
MD5 | c11911714ef1654dce367d8bd79276d6 |
|
BLAKE2b-256 | 3b5e985afd4048babb3f03d682645b85085638ef58305691b35f7be4243e7580 |
Close
Hashes for damo_embedding-1.1.11-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd2a531252eb8cce4e7e65caca3de1b2b664646261e8adaba5495b24ea1440dd |
|
MD5 | 943887dd58866424d09f0cd6d3f9cd97 |
|
BLAKE2b-256 | 829f36371526060635843a9187d657821fa525a45eb34af251e02df7a24ff911 |
Close
Hashes for damo_embedding-1.1.11-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57c905f82def0f5acc0264e1deea1153fec103ebade84abd5bbd8704db06bf06 |
|
MD5 | d7efc5f5c76ac4968095e88e06027fca |
|
BLAKE2b-256 | 8b22663101883adeb61a379bcdbe757eadcdce838d08443090c304ea7cf771e0 |
Close
Hashes for damo_embedding-1.1.11-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6445210356019930ab02ea4327ae12313c242290734aa8819d70c4bdfa2746da |
|
MD5 | d9b9d93f08974cd139a6ae0190b32c71 |
|
BLAKE2b-256 | 8d8e2a9e9cef7b9a6118eeab8536174f1a33be9c913fcc688803c522a6775491 |
Close
Hashes for damo_embedding-1.1.11-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3f42e88c3260128683d3ef37ced22e082df3c4a3990428278d1c350e6ef6077 |
|
MD5 | 5ca6372fbfa2e897eb72bd1fa71cf5fe |
|
BLAKE2b-256 | af0fa1f77a5c4a3e40c5f1ef4407a7e11dde475456979e7965a16e492c991e53 |
Close
Hashes for damo_embedding-1.1.11-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 799440937b562e7afd5faabe5c108ecd6143b19db91cd768118f8dd020c9d76b |
|
MD5 | 10986e184a8baf1e75fd02a45c981fa5 |
|
BLAKE2b-256 | 771fe1b92a3537b34703ba11b3f673800d613c3b7ffc06fcdb1ebe0d8addf548 |
Close
Hashes for damo_embedding-1.1.11-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea84140e85e6a4bb630b00862127adcd067d5b581f0dfd6de547eebfe8a1097f |
|
MD5 | 39d2fdea10ea79bdefffca869f815ca6 |
|
BLAKE2b-256 | 09fb3be17dfbf451a5ab39fc394b50151b67b7969a691aa2c6092a96f7247949 |
Close
Hashes for damo_embedding-1.1.11-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 603608dcb2c84425e4a8deacbc000c57f94e66aac1e0c404e215743ae561157a |
|
MD5 | 295e4bee6d0842716d18697ed38ed67d |
|
BLAKE2b-256 | 3a9edfd7a4f6ec7a3fddc45cde67996325d82f1f261727ef3e07e6feb15de7e7 |
Close
Hashes for damo_embedding-1.1.11-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ec8baa17c08473cb0bb198b08f8b23814386d341bb682bd9d2fe813d2cad5c4 |
|
MD5 | 0a748852abb5c22b4e4b5cda204c489d |
|
BLAKE2b-256 | b4a43614f3d371cef0a14657cce74f149417b4357250bc1ed0f1f1677c601e9f |
Close
Hashes for damo_embedding-1.1.11-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddc2ebb7dfdf1107ff49ea46c706a5847efecb85583973bf63e29fc5e972dc6a |
|
MD5 | 380c824a5e8a69d6ea08d2e2a836ae31 |
|
BLAKE2b-256 | a84dfff54340d53da5eb5a234e210234bddd2b359154b383dae2ed91e80f874c |
Close
Hashes for damo_embedding-1.1.11-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd9f14eaebac4584e2e87c89c06606596fd844b76f90745d63e0509bc67fc3d7 |
|
MD5 | 2facc7469b7c3ae2ef7b83252ab5203e |
|
BLAKE2b-256 | 34a9673441e035206b74544adc271372163303593f25f566a836f4e3c9413f6b |
Close
Hashes for damo_embedding-1.1.11-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2199a650865799c92d7a3e0ab5701e44572c5fb47000300f70124010de761a8e |
|
MD5 | b34e6bdbc7c26098a04462e99e5ed7f0 |
|
BLAKE2b-256 | b951f70a5d768c7d7c7223813950cf04c359250e6ae798ba4d61d71ed972925e |