diff --git a/pumpp/task/beat.py b/pumpp/task/beat.py
index 2d4b56b..cd5a0f3 100644
--- a/pumpp/task/beat.py
+++ b/pumpp/task/beat.py
@@ -4,6 +4,7 @@
 
 import numpy as np
 
+from librosa import time_to_frames
 import jams
 from mir_eval.util import boundaries_to_intervals, adjust_intervals
 from sklearn.preprocessing import LabelBinarizer, LabelEncoder
@@ -95,7 +96,11 @@ class BeatTransformer(BaseTaskTransformer):
 
         ann = jams.Annotation(namespace=self.namespace, duration=duration)
 
-        beat_times = [t for t, _ in self.decode_events(encoded) if _]
+        beat_times = np.asarray([t for t, _ in self.decode_events(encoded) if _])
+        beat_frames = time_to_frames(beat_times,
+                                     sr=self.sr,
+                                     hop_length=self.hop_length)
+
         if downbeat is not None:
             downbeat_times = set([t for t, _ in self.decode_events(downbeat)
                                   if _])
@@ -106,12 +111,16 @@ class BeatTransformer(BaseTaskTransformer):
             pickup_beats = 0
 
         value = - pickup_beats - 1
-        for beat in beat_times:
-            if beat in downbeat_times:
+        for beat_t, beat_f in zip(beat_times, beat_frames):
+            if beat_t in downbeat_times:
                 value = 1
             else:
                 value += 1
-            ann.append(time=beat, duration=0, value=value)
+            confidence = encoded[beat_f]
+            ann.append(time=beat_t,
+                       duration=0,
+                       value=value,
+                       confidence=confidence)
 
         return ann
 
diff --git a/pumpp/task/chord.py b/pumpp/task/chord.py
index 6396124..e07cce2 100644
--- a/pumpp/task/chord.py
+++ b/pumpp/task/chord.py
@@ -9,6 +9,7 @@ import numpy as np
 from sklearn.preprocessing import LabelBinarizer, LabelEncoder
 from sklearn.preprocessing import MultiLabelBinarizer
 
+from librosa import time_to_frames
 import mir_eval
 import jams
 
@@ -492,12 +493,30 @@ class ChordTagTransformer(BaseTaskTransformer):
                                                        duration=duration,
                                                        multi=False,
                                                        sparse=self.sparse):
+
+            # Map start:end to frames
+            f_start, f_end = time_to_frames([start, end],
+                                            sr=self.sr,
+                                            hop_length=self.hop_length)
+
+            # Reverse the index
             if self.sparse:
+                # Compute the confidence
+                if encoded.shape[1] == 1:
+                    # This case is for full-confidence prediction (just the index)
+                    confidence = 1.
+                else:
+                    confidence = np.mean(encoded[f_start:f_end+1, value])
+
                 value_dec = self.encoder.inverse_transform(value)
             else:
+                confidence = np.mean(encoded[f_start:f_end+1, np.argmax(value)])
                 value_dec = self.encoder.inverse_transform(np.atleast_2d(value))
 
             for vd in value_dec:
-                ann.append(time=start, duration=end-start, value=vd)
+                ann.append(time=start,
+                           duration=end-start,
+                           value=vd,
+                           confidence=float(confidence))
 
         return ann
diff --git a/pumpp/task/tags.py b/pumpp/task/tags.py
index 3cbf6a9..8b2f14e 100644
--- a/pumpp/task/tags.py
+++ b/pumpp/task/tags.py
@@ -5,6 +5,8 @@
 import numpy as np
 from sklearn.preprocessing import MultiLabelBinarizer
 
+from librosa import time_to_frames
+
 import jams
 
 from .base import BaseTaskTransformer
@@ -106,10 +108,20 @@ class DynamicLabelTransformer(BaseTaskTransformer):
         ann = jams.Annotation(namespace=self.namespace, duration=duration)
         for start, end, value in self.decode_intervals(encoded,
                                                        duration=duration):
+            # Map start:end to frames
+            f_start, f_end = time_to_frames([start, end],
+                                            sr=self.sr,
+                                            hop_length=self.hop_length)
+
+            confidence = np.mean(encoded[f_start:f_end+1, value])
+
             value_dec = self.encoder.inverse_transform(np.atleast_2d(value))[0]
 
             for vd in value_dec:
-                ann.append(time=start, duration=end-start, value=vd)
+                ann.append(time=start,
+                           duration=end-start,
+                           value=vd,
+                           confidence=confidence)
 
         return ann
 
@@ -185,9 +197,14 @@ class StaticLabelTransformer(BaseTaskTransformer):
         ann = jams.Annotation(namespace=self.namespace, duration=duration)
 
         if np.isrealobj(encoded):
-            encoded = (encoded >= 0.5)
-
-        for vd in self.encoder.inverse_transform(np.atleast_2d(encoded))[0]:
-            ann.append(time=0, duration=duration, value=vd)
-
+            detected = (encoded >= 0.5)
+        else:
+            detected = encoded
+
+        for vd in self.encoder.inverse_transform(np.atleast_2d(detected))[0]:
+            vid = np.flatnonzero(self.encoder.transform(np.atleast_2d(vd)))
+            ann.append(time=0,
+                       duration=duration,
+                       value=vd,
+                       confidence=encoded[vid])
         return ann

Automatic confidence in task inversion
#### Description
The prediction inverters / jams converters could populate the `confidence` field of the jams annotations.

They don't currently, but it would be easy to do so.
diff --git a/tests/test_decode.py b/tests/test_decode.py
index f0ffe6b..cfe297c 100644
--- a/tests/test_decode.py
+++ b/tests/test_decode.py
@@ -101,6 +101,8 @@ def test_decode_tags_dynamic_hard(sr, hop_length, ann_tag):
     data = tc.transform_annotation(ann_tag, ann_tag.duration)
 
     inverse = tc.inverse(data['tags'], duration=ann_tag.duration)
+    for obs in inverse:
+        assert 0. <= obs.confidence <= 1.
     data2 = tc.transform_annotation(inverse, ann_tag.duration)
 
     assert np.allclose(data['tags'], data2['tags'])
@@ -119,6 +121,8 @@ def test_decode_tags_dynamic_soft(sr, hop_length, ann_tag):
     # Soften the data, but preserve the decisions
     tags_predict = data['tags'] * 0.51 + 0.1
     inverse = tc.inverse(tags_predict, duration=ann_tag.duration)
+    for obs in inverse:
+        assert 0. <= obs.confidence <= 1.
     data2 = tc.transform_annotation(inverse, ann_tag.duration)
 
     assert np.allclose(data['tags'], data2['tags'])
@@ -130,6 +134,8 @@ def test_decode_tags_static_hard(ann_tag):
 
     data = tc.transform_annotation(ann_tag, ann_tag.duration)
     inverse = tc.inverse(data['tags'], ann_tag.duration)
+    for obs in inverse:
+        assert 0. <= obs.confidence <= 1.
     data2 = tc.transform_annotation(inverse, ann_tag.duration)
 
     assert np.allclose(data['tags'], data2['tags'])
@@ -143,6 +149,8 @@ def test_decode_tags_static_soft(ann_tag):
     tags_predict = data['tags'] * 0.51 + 0.1
 
     inverse = tc.inverse(tags_predict, ann_tag.duration)
+    for obs in inverse:
+        assert 0. <= obs.confidence <= 1.
     data2 = tc.transform_annotation(inverse, ann_tag.duration)
 
     assert np.allclose(data['tags'], data2['tags'])
@@ -154,6 +162,8 @@ def test_decode_beat_hard(sr, hop_length, ann_beat):
 
     data = tc.transform_annotation(ann_beat, ann_beat.duration)
     inverse = tc.inverse(data['beat'], duration=ann_beat.duration)
+    for obs in inverse:
+        assert 0. <= obs.confidence <= 1.
     data2 = tc.transform_annotation(inverse, ann_beat.duration)
 
     assert np.allclose(data['beat'], data2['beat'])
@@ -167,6 +177,8 @@ def test_decode_beat_soft(sr, hop_length, ann_beat):
     beat_pred = data['beat'] * 0.51 + 0.1
 
     inverse = tc.inverse(beat_pred, duration=ann_beat.duration)
+    for obs in inverse:
+        assert 0. <= obs.confidence <= 1.
     data2 = tc.transform_annotation(inverse, ann_beat.duration)
 
     assert np.allclose(data['beat'], data2['beat'])
@@ -179,6 +191,8 @@ def test_decode_beat_downbeat_hard(sr, hop_length, ann_beat):
     data = tc.transform_annotation(ann_beat, ann_beat.duration)
     inverse = tc.inverse(data['beat'], downbeat=data['downbeat'],
                          duration=ann_beat.duration)
+    for obs in inverse:
+        assert 0. <= obs.confidence <= 1.
     data2 = tc.transform_annotation(inverse, ann_beat.duration)
 
     assert np.allclose(data['beat'], data2['beat'])
@@ -193,6 +207,8 @@ def test_decode_beat_downbeat_soft(sr, hop_length, ann_beat):
     dbeat_pred = data['downbeat'] * 0.51 + 0.1
     inverse = tc.inverse(beat_pred, downbeat=dbeat_pred,
                          duration=ann_beat.duration)
+    for obs in inverse:
+        assert 0. <= obs.confidence <= 1.
     data2 = tc.transform_annotation(inverse, ann_beat.duration)
 
     assert np.allclose(data['beat'], data2['beat'])
@@ -250,6 +266,8 @@ def test_decode_chordtag_hard_dense(sr, hop_length, ann_chord):
     data = tc.transform_annotation(ann_chord, ann_chord.duration)
 
     inverse = tc.inverse(data['chord'], duration=ann_chord.duration)
+    for obs in inverse:
+        assert 0 <= obs.confidence <= 1.
     data2 = tc.transform_annotation(inverse, ann_chord.duration)
 
     assert np.allclose(data['chord'], data2['chord'])
@@ -267,6 +285,10 @@ def test_decode_chordtag_soft_dense(sr, hop_length, ann_chord):
 
     chord_predict = data['chord'] * 0.51 + 0.1
     inverse = tc.inverse(chord_predict, duration=ann_chord.duration)
+
+    for obs in inverse:
+        assert 0 <= obs.confidence <= 1.
+
     data2 = tc.transform_annotation(inverse, ann_chord.duration)
 
     assert np.allclose(data['chord'], data2['chord'])
@@ -283,6 +305,8 @@ def test_decode_chordtag_hard_sparse_sparse(sr, hop_length, ann_chord):
     data = tc.transform_annotation(ann_chord, ann_chord.duration)
 
     inverse = tc.inverse(data['chord'], duration=ann_chord.duration)
+    for obs in inverse:
+        assert 0 <= obs.confidence <= 1.
     data2 = tc.transform_annotation(inverse, ann_chord.duration)
 
     assert np.allclose(data['chord'], data2['chord'])
@@ -305,6 +329,8 @@ def test_decode_chordtag_hard_dense_sparse(sr, hop_length, ann_chord):
 
     # Invert using the sparse encoder
     inverse = tcs.inverse(data['chord'], duration=ann_chord.duration)
+    for obs in inverse:
+        assert 0 <= obs.confidence <= 1.
     data2 = tcs.transform_annotation(inverse, ann_chord.duration)
 
     dense_positions = np.where(data['chord'])[1]
@@ -330,6 +356,8 @@ def test_decode_chordtag_soft_dense_sparse(sr, hop_length, ann_chord):
     chord_predict = data['chord'] * 0.51 + 0.1
     # Invert using the sparse encoder
     inverse = tcs.inverse(chord_predict, duration=ann_chord.duration)
+    for obs in inverse:
+        assert 0 <= obs.confidence <= 1.
     data2 = tcs.transform_annotation(inverse, ann_chord.duration)
 
     dense_positions = np.where(data['chord'])[1]

pip install -e .[docs,tests]
parse_log_pytest
requirements.txt
pytest pyflakes
apt-get update apt-get install -y ffmpeg
3.5
docs/requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
absl-py==0.15.0
alabaster==0.7.13
appdirs==1.4.4
astunparse==1.6.3
attrs==22.2.0
audioread==3.0.1
Babel==2.11.0
cached-property==1.5.2
cachetools==4.2.4
certifi==2021.5.30
cffi==1.15.1
charset-normalizer==2.0.12
clang==5.0
coverage==6.2
dataclasses==0.8
decorator==5.1.1
docutils==0.18.1
flatbuffers==1.12
gast==0.4.0
google-auth==1.35.0
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
grpcio==1.48.2
h5py==3.1.0
idna==3.10
imagesize==1.4.1
importlib-metadata==4.8.3
importlib-resources==5.4.0
iniconfig==1.1.1
jams==0.3.4
Jinja2==3.0.3
joblib==1.1.1
jsonschema==3.2.0
keras==2.6.0
Keras-Preprocessing==1.1.2
librosa==0.9.2
llvmlite==0.36.0
Markdown==3.3.7
MarkupSafe==2.0.1
mir_eval==0.8.2
numba==0.53.1
numpy==1.19.5
numpydoc==1.1.0
oauthlib==3.2.2
opt-einsum==3.3.0
packaging==21.3
pandas==1.1.5
pluggy==1.0.0
pooch==1.6.0
protobuf==3.19.6
-e git+https://github.com/bmcfee/pumpp.git@460d07619ca6d1916150f56b45f333ba500d94a3#egg=pumpp
py==1.11.0
pyasn1==0.5.1
pyasn1-modules==0.3.0
pycparser==2.21
pyflakes==3.0.1
Pygments==2.14.0
pyparsing==3.1.4
pyrsistent==0.18.0
pytest==7.0.1
pytest-cov==4.0.0
python-dateutil==2.9.0.post0
pytz==2025.2
requests==2.27.1
requests-oauthlib==2.0.0
resampy==0.4.3
rsa==4.9
scikit-learn==0.24.2
scipy==1.5.4
six==1.15.0
snowballstemmer==2.2.0
sortedcontainers==2.4.0
soundfile==0.13.1
Sphinx==5.3.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
tensorboard==2.6.0
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
tensorflow==2.6.2
tensorflow-estimator==2.6.0
termcolor==1.1.0
threadpoolctl==3.1.0
tomli==1.2.3
typing-extensions==3.7.4.3
urllib3==1.26.20
Werkzeug==2.0.3
wrapt==1.12.1
zipp==3.6.0

name: pumpp
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - absl-py==0.15.0
      - alabaster==0.7.13
      - appdirs==1.4.4
      - astunparse==1.6.3
      - attrs==22.2.0
      - audioread==3.0.1
      - babel==2.11.0
      - cached-property==1.5.2
      - cachetools==4.2.4
      - cffi==1.15.1
      - charset-normalizer==2.0.12
      - clang==5.0
      - coverage==6.2
      - dataclasses==0.8
      - decorator==5.1.1
      - docutils==0.18.1
      - flatbuffers==1.12
      - gast==0.4.0
      - google-auth==1.35.0
      - google-auth-oauthlib==0.4.6
      - google-pasta==0.2.0
      - grpcio==1.48.2
      - h5py==3.1.0
      - idna==3.10
      - imagesize==1.4.1
      - importlib-metadata==4.8.3
      - importlib-resources==5.4.0
      - iniconfig==1.1.1
      - jams==0.3.4
      - jinja2==3.0.3
      - joblib==1.1.1
      - jsonschema==3.2.0
      - keras==2.6.0
      - keras-preprocessing==1.1.2
      - librosa==0.9.2
      - llvmlite==0.36.0
      - markdown==3.3.7
      - markupsafe==2.0.1
      - mir-eval==0.8.2
      - numba==0.53.1
      - numpy==1.19.5
      - numpydoc==1.1.0
      - oauthlib==3.2.2
      - opt-einsum==3.3.0
      - packaging==21.3
      - pandas==1.1.5
      - pluggy==1.0.0
      - pooch==1.6.0
      - protobuf==3.19.6
      - py==1.11.0
      - pyasn1==0.5.1
      - pyasn1-modules==0.3.0
      - pycparser==2.21
      - pyflakes==3.0.1
      - pygments==2.14.0
      - pyparsing==3.1.4
      - pyrsistent==0.18.0
      - pytest==7.0.1
      - pytest-cov==4.0.0
      - python-dateutil==2.9.0.post0
      - pytz==2025.2
      - requests==2.27.1
      - requests-oauthlib==2.0.0
      - resampy==0.4.3
      - rsa==4.9
      - scikit-learn==0.24.2
      - scipy==1.5.4
      - six==1.15.0
      - snowballstemmer==2.2.0
      - sortedcontainers==2.4.0
      - soundfile==0.13.1
      - sphinx==5.3.0
      - sphinxcontrib-applehelp==1.0.2
      - sphinxcontrib-devhelp==1.0.2
      - sphinxcontrib-htmlhelp==2.0.0
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==1.0.3
      - sphinxcontrib-serializinghtml==1.1.5
      - tensorboard==2.6.0
      - tensorboard-data-server==0.6.1
      - tensorboard-plugin-wit==1.8.1
      - tensorflow==2.6.2
      - tensorflow-estimator==2.6.0
      - termcolor==1.1.0
      - threadpoolctl==3.1.0
      - tomli==1.2.3
      - typing-extensions==3.7.4.3
      - urllib3==1.26.20
      - werkzeug==2.0.3
      - wrapt==1.12.1
      - zipp==3.6.0
prefix: /opt/conda/envs/pumpp

tests/test_decode.py::test_decode_tags_dynamic_hard tests/test_decode.py::test_decode_tags_dynamic_soft tests/test_decode.py::test_decode_tags_static_hard tests/test_decode.py::test_decode_tags_static_soft tests/test_decode.py::test_decode_beat_hard tests/test_decode.py::test_decode_beat_soft tests/test_decode.py::test_decode_beat_downbeat_hard tests/test_decode.py::test_decode_beat_downbeat_soft tests/test_decode.py::test_decode_chordtag_hard_dense tests/test_decode.py::test_decode_chordtag_soft_dense tests/test_decode.py::test_decode_chordtag_hard_sparse_sparse tests/test_decode.py::test_decode_chordtag_hard_dense_sparse tests/test_decode.py::test_decode_chordtag_soft_dense_sparse
tests/test_decode.py::test_decode_vector
pumpp/task/tags.py pumpp/task/chord.py pumpp/task/beat.py
pumpp/task/tags.py pumpp/task/chord.py pumpp/task/beat.py