tensorflow / tensorflow/probability
Errors related to `name` argument in tfp.sts package
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
Hi, thank you for providing a great product.
I'm trying to build a model with tfp.sts package but I'm facing issues around the name argument.
TypeError: tensorflow_probability.python.sts.components.autoregressive.AutoregressiveStateSpaceModel() got multiple values for keyword argument 'name'
Script
import tensorflow_probability as tfp
tfd = tfp.distributions
if __name__ == "__main__":
components = [tfp.sts.Autoregressive(order=1, name="ar")]
components_params = {"ar/_coefficients": [1.], "ar/_level_scale": [1.]}
s = tfp.sts.Sum(components, name="sum")
ssm = s.make_state_space_model(
num_timesteps=100,
param_vals={
"observation_noise_scale": 1e-1,
**components_params,
},
name="ssm"
)
print(f"{ssm.name} is built successfully")
Error
Traceback (most recent call last):
File "/Users/hiroki/dev/tensorflow-probability-issue/example.py", line 21, in <module>
ssm = s.make_state_space_model(
File "/Users/hiroki/Library/Caches/pypoetry/virtualenvs/tensorflow-probability-issue-_b8RfAk--py3.10/lib/python3.10/site-packages/tensorflow_probability/python/sts/structural_time_series.py", line 244, in make_state_space_model
return self._make_state_space_model(
File "/Users/hiroki/Library/Caches/pypoetry/virtualenvs/tensorflow-probability-issue-_b8RfAk--py3.10/lib/python3.10/site-packages/tensorflow_probability/python/sts/components/sum.py", line 555, in _make_state_space_model
component_ssms = self.make_component_state_space_models(
File "/Users/hiroki/Library/Caches/pypoetry/virtualenvs/tensorflow-probability-issue-_b8RfAk--py3.10/lib/python3.10/site-packages/tensorflow_probability/python/sts/components/sum.py", line 537, in make_component_state_space_models
component.make_state_space_model(
File "/Users/hiroki/Library/Caches/pypoetry/virtualenvs/tensorflow-probability-issue-_b8RfAk--py3.10/lib/python3.10/site-packages/tensorflow_probability/python/sts/structural_time_series.py", line 244, in make_state_space_model
return self._make_state_space_model(
File "/Users/hiroki/Library/Caches/pypoetry/virtualenvs/tensorflow-probability-issue-_b8RfAk--py3.10/lib/python3.10/site-packages/tensorflow_probability/python/sts/components/autoregressive.py", line 415, in _make_state_space_model
return AutoregressiveStateSpaceModel(
TypeError: tensorflow_probability.python.sts.components.autoregressive.AutoregressiveStateSpaceModel() got multiple values for keyword argument 'name'
ValueError: Field names must be valid identifiers: arima/
Script
import tensorflow_probability as tfp
tfd = tfp.distributions
if __name__ == "__main__":
model = tfp.sts.AutoregressiveIntegratedMovingAverage(0, 0, 1, name="arima")
@tfd.JointDistributionCoroutine
def joint_distribution():
yield tfd.JointDistribution.Root(model.make_state_space_model(1, [1.]))
print(joint_distribution.log_prob([[[0.]]]))
Error
WARNING:tensorflow:From /Users/hiroki/Library/Caches/pypoetry/virtualenvs/tensorflow-probability-issue-_b8RfAk--py3.10/lib/python3.10/site-packages/tensorflow_probability/python/distributions/distribution.py:342: calling MultivariateNormalDiag.__init__ (from tensorflow_probability.python.distributions.mvn_diag) with scale_identity_multiplier is deprecated and will be removed after 2020-01-01.
Instructions for updating:
`scale_identity_multiplier` is deprecated; please combine it into `scale_diag` directly instead.
Traceback (most recent call last):
File "/Users/hiroki/dev/tensorflow-probability-issue/example.py", line 36, in <module>
print(joint_distribution.log_prob([[[0.]]]))
File "/Users/hiroki/Library/Caches/pypoetry/virtualenvs/tensorflow-probability-issue-_b8RfAk--py3.10/lib/python3.10/site-packages/tensorflow_probability/python/distributions/joint_distribution.py", line 897, in log_prob
return self._call_log_prob(self._resolve_value(*args, **kwargs), name=name)
File "/Users/hiroki/Library/Caches/pypoetry/virtualenvs/tensorflow-probability-issue-_b8RfAk--py3.10/lib/python3.10/site-packages/tensorflow_probability/python/distributions/joint_distribution.py", line 808, in _resolve_value
dtype=self.dtype,
File "/Users/hiroki/Library/Caches/pypoetry/virtualenvs/tensorflow-probability-issue-_b8RfAk--py3.10/lib/python3.10/site-packages/tensorflow_probability/python/distributions/joint_distribution.py", line 388, in dtype
return self._model_unflatten(
File "/Users/hiroki/Library/Caches/pypoetry/virtualenvs/tensorflow-probability-issue-_b8RfAk--py3.10/lib/python3.10/site-packages/tensorflow_probability/python/distributions/joint_distribution_coroutine.py", line 361, in _model_unflatten
return structural_tuple.structtuple(self._flat_resolve_names())(*xs)
File "/Users/hiroki/Library/Caches/pypoetry/virtualenvs/tensorflow-probability-issue-_b8RfAk--py3.10/lib/python3.10/site-packages/tensorflow_probability/python/internal/structural_tuple.py", line 73, in structtuple
_validate_field_names(field_names)
File "/Users/hiroki/Library/Caches/pypoetry/virtualenvs/tensorflow-probability-issue-_b8RfAk--py3.10/lib/python3.10/site-packages/tensorflow_probability/python/internal/structural_tuple.py", line 48, in _validate_field_names
raise ValueError('Field names must be valid identifiers: {}'.format(name))
ValueError: Field names must be valid identifiers: arima/
Minimal reproducible example
I created a project to reproduce these errors.
After checking out, please install the dependencies:
- For M1 mac:
poetry install --without tf --with tf_apple_silicon - For other env:
poetry install- Please note that I'm using an M1 mac so this version isn't tested well.
Then, you can reproduce the above errors on each branch:
- multiple-name-args branch
TypeError: tensorflow_probability.python.sts.components.autoregressive.AutoregressiveStateSpaceModel() got multiple values for keyword argument 'name'poetry run python example.py=> Reproduce the above error:tfp.sts.Autoregressivecauses the errorpoetry run python example.py successful=> Normal case:tfp.sts.LocalLevelworks without any error
- invalid-name branch
ValueError: Field names must be valid identifiers: arima/poetry run python example.py=> Reproduce the above error: The combination oftfp.sts.AutoregressiveIntegratedMovingAverageandtfd.JointDistributionCoroutinecauses the errorpoetry run python example.py locallevel=> Normal case:tf.sts.LocalLevel&tfd.JointDistributionCoroutineworks without any errorpoetry run python example.py sequential=> Normal case:tf.sts.AutoregressiveIntegratedMovingAverage&tfd.JointDistributionSequentialworks without any errorpoetry run python example.py named=> Normal case:tf.sts.AutoregressiveIntegratedMovingAverage&tfd.JointDistributionSequentialworks without any error
Does someone have any thoughts on how to resolve these issues?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the two reproductions with the multiple-name-args and invalid-name branches using the listed Poetry commands. Start with structural_time_series.py, components/autoregressive.py, components/sum.py, joint_distribution_coroutine.py, and structural_tuple.py, following the stack traces. Done means both reported examples run without the duplicate-name or invalid-identifier errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100