@@ -107,6 +107,34 @@ def softmin(
107
107
)
108
108
109
109
110
+ def softmax_scalefree (
111
+ * args : Union [float , _np .ndarray ],
112
+ relative_softness : float = 1e-2 ,
113
+ relative_hardness : float = None ,
114
+ ) -> Union [float , _np .ndarray ]:
115
+ if not (relative_softness is None ) ^ (relative_hardness is None ):
116
+ raise ValueError ("You must provide exactly one of `relative_softness` or `relative_hardness." )
117
+ if relative_hardness is not None :
118
+ relative_softness = 1 / relative_hardness
119
+
120
+ return softmax (
121
+ * args ,
122
+ softness = relative_softness * _np .linalg .norm (_np .array (args ))
123
+ )
124
+
125
+
126
+ def softmin_scalefree (
127
+ * args : Union [float , _np .ndarray ],
128
+ relative_softness : float = 1e-2 ,
129
+ relative_hardness : float = None ,
130
+ ) -> Union [float , _np .ndarray ]:
131
+ return - softmax_scalefree (
132
+ * [- arg for arg in args ],
133
+ relative_softness = relative_softness ,
134
+ relative_hardness = relative_hardness ,
135
+ )
136
+
137
+
110
138
def sigmoid (
111
139
x ,
112
140
sigmoid_type : str = "tanh" ,
0 commit comments