Comments (3)
Here is my proposed function:
def cross_entropy_logits_sparse(logits: JaxArray, labels: Union[JaxArray, int]) -> JaxArray:
"""Computes the softmax cross-entropy loss.
Args:
logits: (batch, ..., #class) tensor of logits.
labels: (batch, ...) integer tensor of label indexes in {0, ...,#nclass-1} or just a single integer.
Returns:
(batch, ....) tensor of the cross-entropies for each entry.
"""
if isinstance(labels, int):
labeled_logits = logits[..., labels]
else:
labeled_logits = jn.take_along_axis(logits, labels[..., None], -1).squeeze(-1)
return logsumexp(logits, axis=-1) - labeled_logits
Side note: after a few hours using objax, I think your ideas on Module and (Trainable & State)-Variable are brilliant!
from objax.
Yes, we could extend this API to support multi-dimensional (>=2) tensors.
from objax.
Your proposed function looks nice! Would you like to create a PR?
from objax.
Related Issues (20)
- If user won't add random generator to VarCollection of jitted code then same number always return by random generator
- Model compiling twice when using jax==0.2.10 or later HOT 6
- Update Objax Basics tutorial to reflect .value change
- Accessing variable of a vectorized module HOT 2
- objax.Jit reports error when StateVar is added to the vc argument HOT 3
- Regression of JAX duck typing. HOT 2
- RecursionError when attempting to unpickle objax objects HOT 2
- How to compute Jacobian of outputs w.r.t. inputs HOT 3
- Activation functions like Swish and Mish are absent. HOT 1
- Error due to the deprecation of jax.api
- objax.Jacobian and objax.Hessian similar to objax.Grad HOT 4
- replacing jax.vmap with objax.Vectorize HOT 3
- Closure scoping for nested objax.Functions HOT 2
- ResNetV2 from model.zoo does not specify train arg for ResNetV2Block HOT 2
- pmean inside objax.parallel causes multithreading deadlock for more than 2 gpus HOT 3
- `objax.variable.VarCollection.update` fails when passing `Dict[str, Any]` HOT 1
- `objax.variable.VarCollection.update` not compliant with key-value assignment HOT 1
- TypeError during gradient computation: type <class 'objax.variable.TrainVar'> is not a valid JAX type
- Missing release 1.7.0 on GitHub HOT 2
- [Jax 0.4.27] AttributeError: arr.device_buffers has been deprecated.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from objax.